我写了个购物车的JSP代码,如下:
<html>
<head>
<title>添加购物车</title>
</head>
<style type="text/css">
<body bgcolor="#FFFFFF">
<%@ page import="java.sql.*"%>
<jsp:useBean id="conn" scope="page" class="myshop.conn"/>
<%@ page import="buylist.buylist"%>
<%
String ISBN=request.getParameter("isbn");
String TITLE="";
String PRICE="";
String sql="select TITLE,PRICE from bookinfo where ISBN='"+ISBN+"'";
ResultSet rs=conn.executeQuery(sql);
if(rs.next())
{TITLE=rs.getString("TITLE");
PRICE=rs.getString("PRICE");
}
buylist mylist=new buylist();
mylist.TITLE=TITLE;
mylist.ISBN=ISBN;
mylist.number=1;
boolean listFlag=true;
Vector shop=(Vector)session.getValue("shop");
if(shop==null)
{shop=new Vector();
}
else
{
for(int i=0;i<shop.size();i++)
{buylist list=(buylist)shop.elementAt(i);
if(list.ISBN==mylist.ISBN)
{list.number++;
shop.setElementAt(list,i);
listFlag=false;
}
}
if(listFlag)shop.addElement(mylist);
session.putValue("shop".shop);
rs.close();
%>
<br><font size="4" color="#FF0033">您选购的书籍已经成功的添加到购物车中!</font></b><br>
<br>
<a href="JaavaScript:window.close()">关闭窗口</a>
<a href="list.jsp target="_blank" onclick="javaScript:window.close()">查看购物车
</a></div>
</body>
</html>
上面的mysho.conn javabean 没问题,可能问题出在那个buylist 类
package buylist;
public class buylist
{public String TITLE;
public int id;
public int number;
public String PRICE;
public String ISBN;
}
运行后显示如下:
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 Generated servlet error: Syntax error, insert "}" to complete Block Generated servlet error: Syntax error on token "}", delete this token Generated servlet error: Syntax error, insert "}" to complete ClassBody org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:510) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:375) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264) javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
root cause
org.apache.jasper.JasperException: Unable to compile class for JSP Generated servlet error: Syntax error, insert "}" to complete Block Generated servlet error: Syntax error on token "}", delete this token Generated servlet error: Syntax error, insert "}" to complete ClassBody org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84) org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:328) org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:409) org.apache.jasper.compiler.Compiler.compile(Compiler.java:297) org.apache.jasper.compiler.Compiler.compile(Compiler.java:276) org.apache.jasper.compiler.Compiler.compile(Compiler.java:264) org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:563) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:303) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264) javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
note The full stack trace of the root cause is available in the Apache Tomcat/5.5.15 logs.