|
这段代码,我执行时出错如下;
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:358)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
root cause
java.lang.NullPointerException
bean.jdbcBean.closeDB(jdbcBean.java:41)
org.apache.jsp.checkout_jsp._jspService(checkout_jsp.java:172)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
note The full stack trace of the root cause is available in the Tomcat logs.
源码:
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>网上碟店:碟碟不休</title>
</head>
<body>
<%@ include file="header.jsp"%>
<table width="800" height="400" border="1" align="center">
<tr>
<td><%
Vector buylist = (Vector)session.getValue("shopcar");
if(buylist==null||buylist.size()<1)
{
%>
<jsp:forward page="mydisk.jsp"></jsp:forward>
<%}
String userid = (String)session.getValue("uid");
float pricenum =0;
for(int i=0;i<buylist.size();i++)
{
Disk disk = (Disk)buylist.elementAt(i);
pricenum = pricenum + disk.getBuynum()*disk.getPrice();
}
jdbcBean diskBean1=new jdbcBean();
String sql1="INSERT INTO myorder(user_id, price_num, order_time) VALUES('"+userid+"',"+pricenum+",'"+current_time+"')";
int m=diskBean1.executeUpdate(sql1) ;
diskBean1.closeDB();
jdbcBean diskBean2=new jdbcBean();
String sql2="SELECT order_id FROM myorder WHERE order_id='"+userid+"' AND order_time='"+current_time+"'";
ResultSet rs=diskBean2.executeQuery(sql2) ;
rs.next();
String orderid = rs.getString("order_id");
diskBean2.closeDB();
for(int j=0; j<buylist.size(); j++)
{
Disk disk = (Disk)buylist.elementAt(j);
jdbcBean diskBean3=new jdbcBean();
String sql3="INSERT INTO orderitem(order_id, sno, disk_num) VALUES('"+orderid+"','"+disk.getSno()+"','"+disk.getBuynum()+"')";
int mm=diskBean3.executeUpdate(sql3);
diskBean3.closeDB();
}
%></td>
</tr>
</table>
<%@ include file="footer.jsp"%>
</body>
</html>
我已在header.jsp中包含了所需的包<%@ page import="java.io.*"%>
<%@ page import="java.util.*"%>
<%@ page import="java.sql.*"%>
<%@ page import="java.text.*"%>
<%@ page import="bean.*"%>
上面代码在然出错,但是它还是能在数据表myorder中插入了数据,期待各位的帮助!! |
|