gpt4 book ai didi

java - HTTP 状态 500 - 无法编译 JSP : import cannot be resolved to a type 的类

转载 作者:行者123 更新时间:2023-12-01 12:39:59 31 4
gpt4 key购买 nike

以下是我在 jsp 文件中的代码:

int s_id = session.getAttribute("s_id") != null ? ((Integer)     session.getAttribute("s_id")).intValue() : 0 ;
String Pending = "Pending";
%>
<!-- <jsp:useBean id="link" scope="application" class = "Shop" /> -->
<%
Shop s = new Shop();
int g_orderQuantity=0;

错误:

HTTP Status 500 - 
--------------------------------------------------------------------------------
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: Unable to compile class for JSP:

An error occurred at line: 30 in the jsp file: /ShopViewOrder.jsp
Shop cannot be resolved to a type
line 30 : <!-- <jsp:useBean id="link" scope="application" class = "Shop" /> -->

An error occurred at line: 32 in the jsp file: /ShopViewOrder.jsp
Shop cannot be resolved to a type
line 32 : Shop s = new Shop();

页面上的一些答案:"Import cannot be resolved" with JSP建议使用页面导入指令,如下所示: <%@ page import="pkgname.Class1"%>他们认为你必须给出类的完全限定名称。

我已将 Shop 类放置如下:C:\Users\Documents\ShopSystem-AWSJavaWebProject\src\myPackage\Shop.java现在我尝试使用以下语法: <%@ page import="myPackage.Shop"%>但这也不起作用...它给出一个错误,指出无法解析 import myPackage!

然后按照:Eclipse is not importing classes in jsp files中提到的解决方案我已确保启用首选项->导入->Web->Jsp 文件->编辑器->内容辅助->Add_import_instead_of_qualified_name现在当我使用上面的行时:<%@ page import="myPackage.Shop"%>我现在收到以下错误:

exception : org.apache.jasper.JasperException: Unable to compile class for JSP: 

An error occurred at line: 16 in the generated java file
Only a type can be imported. myPackage.Shop resolves to a package

An error occurred at line: 31 in the jsp file: /ShopViewOrder.jsp
Shop cannot be resolved to a type
line 31: <!-- <jsp:useBean id="link" scope="application" class = "Shop" /> -->

An error occurred at line: 33 in the jsp file: /ShopViewOrder.jsp
Shop cannot be resolved to a type
line 33 : Shop s = new Shop();

另一页:problem in importing java class in jsp建议<%@ page language="java" import="yourpackage.subpackage.*,java.util.*" %>因此我将代码更新为:

<%@ page language="java" import="myPackage.Shop" %>

但是错误仍然存​​在!

我什至尝试过以下方法:

<%@ page language="java" import="myPackage.Shop" session="true"%>

按照 To import class to JSP in Tomcat6 上的建议但错误定义没有改变!

在另一个网站上,它说创建要加载的类的公共(public)构造函数。我不知道这有什么帮助,我什至尝试过这也行不通!

请帮忙...

按照要求,我添加了整个代码的片段:

int s_id = session.getAttribute("s_id") != null ? ((Integer) session.getAttribute("s_id")).intValue() : 0 ;
String Pending = "Pending";
<jsp:useBean id="link" scope="application" class = "myPackage.Shop" />
myPackage.Shop s = new myPackage.Shop();
int g_orderQuantity=0;
Statement stmt6 = con.createStatement();
// a shop can select values from Order table
ResultSet rs3 = stmt6.executeQuery("SELECT * FROM ShopSystem.Order where s_id="+s_id+" AND status='"+Pending+"'");
//code to declare some Vectors
while(rs3.next())
{
status1.add((i),rs3.getString("status"));
status=status1.elementAt(i);
// in the above way am adding ResultSet values to the vector and then copying it to string.
//i maintains the total count of all my orders
i++;
}
for(int j=0; j<i; j++)
{
//checking if the order table is empty
if((g_quantityRequired == 0)||(Cust_address.equals(null))||(email.equals(null))||((contact.equals(null)))||(total_amount == 0))
{ %> <br> There are no pending orders. <br>
<%
%> <form name="Back" method="post" action="ShopMenu3.jsp">
<input type="submit" value="Back">
</form><br><br> <%
}
// Now that the order table is not empty continue to process the order..
int g_available=0;
//check availability of g_id in s_id
boolean b_availability = s.checkAvailability_perShop(s_id, g_id, g_quantityRequired);
//if sufficient quantity is not available then place an order
if(b_availability == false)
{ // example, if required=50, then order is placed for 100 items
// but if required is 150, then order is placed for 150 items
g_orderQuantity = (100>g_quantityRequired)?100 : (g_quantityRequired+100);
//placing order and updating the Grocery_perShop table return the amount available of g_id in s_id
g_available = s.placeOrder_perShop(s_id, g_id, g_orderQuantity);
} %>
New g_avaliable = <%= g_available %>. The value has been updated in the database.
<% //now that sufficient g_id is available with s_id, we execute the order
//updating the Grocery_perShop table
g_available = g_available - g_quantityRequired;
//code to insert updated values in table

sc.close();
%> <form name="Back" method="post" action="ShopMenu3.jsp">
<input type="submit" value="Back">
</form><br><br>

最佳答案

如果您尝试访问的类位于应用程序的 mypackage 下(其中包含 jsp 文件),则以下语句应该有效,

<jsp:useBean id="link" scope="application" class = "mypackage.Shop" />

完成构建后检查是否有文件。当您使用 Eclipse 时,请在 build->classes 下进行检查。

关于java - HTTP 状态 500 - 无法编译 JSP : import cannot be resolved to a type 的类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25200052/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com