JSP抛出错误如何解决啊 java.lang.NullPointerException
JSP抛出异常怎么解决啊 java.lang.NullPointerException
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
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:370)
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
java.lang.NullPointerException
bookstoreonline.run.op_buy.payout(op_buy.java:320)
org.apache.jsp.shopcar_jsp._jspService(org.apache.jsp.shopcar_jsp:122)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)
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.12 logs.
/**
* 提交购物车
* @param newrequest
* @return
* @throws java.lang.Exception
*/
public boolean payout(HttpServletRequest newrequest) throws Exception {
request = newrequest;
session = request.getSession(false);
// System.out.print("f1");
if (session == null) {
return false;
}
String Userid = (String) session.getAttribute("userid"); //取得用户ID号
long userid = 0;
if (Userid == null || Userid.equals("")) {
isLogin = false;
return false;
}
else {
try {
userid = Long.parseLong(Userid);
}
catch (NumberFormatException e) {
// System.out.print(e.getMessage());
return false;
}
}
System.out.println("f2");
purchaselist = (Vector) session.getAttribute("shopcar");
if (purchaselist == null || purchaselist.size() < 0) {
return false;
}
String Content = request.getParameter("content");
if (Content == null) {
Content = "";
}
// System.out.print("f3");
Content = getGbk(Content);
String IP = request.getRemoteAddr();
String TotalPrice = request.getParameter("totalprice");
long timeInMillis = System.currentTimeMillis();
//System.out.println("f4");
sqlStr = "insert into orders (orderId,UserId,SubmitTime,ConsignmentTime,TotalPrice,content,IPAddress,IsPayoff,IsSales) values (";
orderId=""+timeInMillis;//以系统时间产生位移的订单编号
sqlStr = sqlStr + orderId + ",'";
sqlStr = sqlStr + userid + "',now(),now()+7,'";
sqlStr = sqlStr + TotalPrice + "','";
sqlStr = sqlStr + dataFormat.toSql(Content) + "','";
sqlStr = sqlStr + IP + "',1,1)";
// System.out.print(sqlStr);
//String setIdSql="udate orders set orderid=orderid+id where UserId = " + userid;
try {
stmt.execute(sqlStr);
//stmt.execute(setIdSql);
// sqlStr = "select max(id) from orders where UserId = " + userid;
// rs = stmt.executeQuery(sqlStr);
//long indentid = 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
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:370)
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
java.lang.NullPointerException
bookstoreonline.run.op_buy.payout(op_buy.java:320)
org.apache.jsp.shopcar_jsp._jspService(org.apache.jsp.shopcar_jsp:122)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)
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.12 logs.
/**
* 提交购物车
* @param newrequest
* @return
* @throws java.lang.Exception
*/
public boolean payout(HttpServletRequest newrequest) throws Exception {
request = newrequest;
session = request.getSession(false);
// System.out.print("f1");
if (session == null) {
return false;
}
String Userid = (String) session.getAttribute("userid"); //取得用户ID号
long userid = 0;
if (Userid == null || Userid.equals("")) {
isLogin = false;
return false;
}
else {
try {
userid = Long.parseLong(Userid);
}
catch (NumberFormatException e) {
// System.out.print(e.getMessage());
return false;
}
}
System.out.println("f2");
purchaselist = (Vector) session.getAttribute("shopcar");
if (purchaselist == null || purchaselist.size() < 0) {
return false;
}
String Content = request.getParameter("content");
if (Content == null) {
Content = "";
}
// System.out.print("f3");
Content = getGbk(Content);
String IP = request.getRemoteAddr();
String TotalPrice = request.getParameter("totalprice");
long timeInMillis = System.currentTimeMillis();
//System.out.println("f4");
sqlStr = "insert into orders (orderId,UserId,SubmitTime,ConsignmentTime,TotalPrice,content,IPAddress,IsPayoff,IsSales) values (";
orderId=""+timeInMillis;//以系统时间产生位移的订单编号
sqlStr = sqlStr + orderId + ",'";
sqlStr = sqlStr + userid + "',now(),now()+7,'";
sqlStr = sqlStr + TotalPrice + "','";
sqlStr = sqlStr + dataFormat.toSql(Content) + "','";
sqlStr = sqlStr + IP + "',1,1)";
// System.out.print(sqlStr);
//String setIdSql="udate orders set orderid=orderid+id where UserId = " + userid;
try {
stmt.execute(sqlStr);
//stmt.execute(setIdSql);
// sqlStr = "select max(id) from orders where UserId = " + userid;
// rs = stmt.executeQuery(sqlStr);
//long indentid = 0;