以下是我在jsp文件中的代码:
int s_id = session.getAttribute("s_id") != null ? ((Integer) session.getAttribute("s_id")).intValue() : 0 ;
String Pending ="Pending";
%>
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 :
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();
页面上的一些答案:使用JSP时"无法解决导入"
建议使用页面导入指令,如下所示:
他们坐在那里,必须给班级一个完全合格的名字。
我将Shop类放置如下:C: Users Documents ShopSystem-AWSJavaWebProject src myPackage Shop.java
现在,我尝试使用以下语法:
但这也不起作用。。。它给出一个错误,提示无法解析导入myPackage!
然后按照中提到的解决方案:Eclipse不会在jsp文件中导入类
我已确保启用了"首选项"->"导入"->" Web"->" Jsp文件"->"编辑器"->"内容辅助"->" Add_import_instead_of_qualified_name"
现在,当我使用上述行时:
我现在收到以下错误:
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:
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();
另一页:在jsp中导入java类时出现问题
建议
因此,我将代码更新为:
但是错误仍然保持不变!
我什至尝试了以下方法:
如在Tomcat6中将类导入到JSP中所建议的
尚未更改错误定义!
在另一个站点上,它说创建要加载的类的公共构造函数。
我不知道这对我有什么帮助,我什至尝试过那也不起作用!
请帮忙...
根据要求-添加我的整个代码段:
int s_id = session.getAttribute("s_id") != null ? ((Integer) session.getAttribute("s_id")).intValue() : 0 ;
String Pending ="Pending";
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
{
//checking if the order table is empty
if((g_quantityRequired == 0)||(Cust_address.equals(null))||(email.equals(null))||((contact.equals(null)))||(total_amount == 0))
{ %> There are no pending orders.
%>
}
// 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 = . The value has been updated in the database.
//updating the Grocery_perShop table
g_available = g_available - g_quantityRequired;
//code to insert updated values in table
sc.close();
%>
注意:s_id代表商店ID,g_id代表杂货店ID,所有以" g"开头的变量均指杂货店,而" s"代表商店
尽量避免使用Scriplet。
如果您要访问的类在application的mypackage下,则在其中具有jsp文件的位置,以下语句应该可以工作,
完成构建后,检查是否有文件。 在使用eclipse时检查build-> classs下的内容。
它说"未定义的类型:myPackage.Shop"。 我已将上述行放置在所有其他相关导入语句的下方以及html标记开始的上方
请分享相关代码以使其清晰明了,并尽量避免使用Scriplet。
哦,对了,我摆脱了未定义的类型错误,现在bt收到以下错误:异常org.apache.jasper.JasperException:/ShopViewOrder.jsp(14,0)useBean类属性myPackage.Shop的值无效 。
检查bean类的名称
您必须为中的类使用完全限定的名称。 不考虑import页面指令
直接来自Oracle官方文档-创建和使用JavaBeans组件
The value supplied for the class attribute must be a fully qualified class name.
Note that beans cannot be in the unnamed package. Thus the format of the value must be package-name.class-name.