以下是我在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"%>
但这也不起作用......它给出了一个错误,说导入myPackage无法解决!
然后按照Eclipse is not importing classes in jsp files中提到的解决方案
我确保已启用偏好设置&gt; import-&gt; Web-&gt; 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的建议 但错误定义没有变化!
在另一个网站上,它表示要创建要加载的类的公共构造函数。 我不知道这有多大帮助,我甚至尝试过那也行不通!
请帮忙......
正如我要求添加整个代码的片段:
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>
答案 0 :(得分:1)
如果您尝试访问的类位于应用程序的mypackage
下,那么您将拥有jsp文件,以下语句应该可用,
<jsp:useBean id="link" scope="application" class = "mypackage.Shop" />
在完成构建后检查是否有文件。在使用eclipse时检查build-&gt;类。
答案 1 :(得分:0)
您必须在<jsp:useBean>
中为班级使用完全限定名称。 import
<jsp:useBean>
页面指令
<jsp:useBean id="link" scope="application" class = "mypackage.Shop" />
直接来自官方Oracle Documentation - Creating and Using a JavaBeans Component
为class属性提供的值必须是
fully qualified class name
。请注意,bean不能位于未命名的包中。因此,值的格式必须为
package-name.class-name
。