困扰一天的购物车问题!
我先写了一个购车车的类,然后在JSP中导入调用它,但是它竟然说无法识别那个Shopcart类,但我明明已经导入了啊!望兄弟们赐教,在此先谢过啦!
代码如下:
Shopcart.java :
package com.bookshop.bean;
public class Shopcart {
public int bookID;
public String bookName;
public String ISBN;
public float price;
public int number;
}
cart_add.jsp :
<%@ page contentType= "text/html;charset=GBK "language= "java " import= "java.util.*,java.sql.*,com.bookshop.bean.* " pageEncoding= "GBK "%>
<jsp:useBean id= "con " scope= "page " class= "com.bookshop.bean.connDB "/>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN ">
<html>
<head>
<title> cart_add </title>
<%
request.setCharacterEncoding( "GBK ") ;
int bookID = Integer.parseInt(request.getParameter( "bookID "));
String sql = "select * from books where bookID= ' "+bookID+ " ' ";
ResultSet rs = con.executeQuery(sql);
float price = 0;
if(rs.next()){
price = rs.getInt( "price ");
}
Shopcart bookelement = new Shopcart();
bookelement.bookID = bookID;
bookelement.price = price;
bookelement.number = 1;
boolean flag = true;
Vector cart = (Vector)session.getAttribute( "cart ");
if(cart==null){
cart = new Vector();
}else{
for(int i=1;i <cart.size();i++){
Shopcart bookitem = (Shopcart)cart.elementAt(i);
if(bookitem.bookID==bookelement.bookID){
bookitem.number++;
cart.setElementAt(bookitem,i);
flag = false;
}
}
}
if(flag){
cart.addElement(bookelement);
session.setAttribute( "cart ",cart);
con.close();
out.println( " <script language= 'javascript '> alert( '已经添加至购物车! ');window.location.href= 'cart_see.jsp '; </script> ");
}
%>
</head>
<body>
</body>
</html>
出现的错误:
org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: 9 in the jsp file: /bookshop/WebRoot/cart_add.jsp
Generated servlet error:
D:\Tomcat5.0\work\Catalina\localhost\test\org\apache\jsp\bookshop\WebRoot\cart_005fadd_jsp.java:73: 找不到符号
符号: 类 Shopcart
位置: 类 org.apache.jsp.bookshop.WebRoot.cart_005fadd_jsp
Shopcart bookelement = new Shopcart();
^
An error