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;
// while (rs.next()) {
// indentid = rs.getLong(1);
//}
//rs.close();
for (int i = 0; i < purchaselist.size(); i++) {
allorder iList = (allorder) purchaselist.elementAt(i);
sqlStr =
"insert into allorder (orderId,BookNo,Amount) values (";
sqlStr = sqlStr + orderId + ",'";
sqlStr = sqlStr + iList.getBookNo() + "','";
sqlStr = sqlStr + iList.getAmount() + "')";
stmt.execute(sqlStr);
sqlStr = "update book set leav_number=leav_number - " +
iList.getAmount() + " where id = " + iList.getBookNo();
stmt.execute(sqlStr);
}
return true;
}
catch (SQLException e) {
System.out.print(e.getMessage());
return false;
}
}
/**
* 查询指定用户id的所有订单
* @param userid
* @return
*/
public boolean getOrder(long userid) {
sqlStr = "select * from orders where userid = '" + userid +
"' order by id desc";
try {
DBConnection db = new DBConnection();
db.getConn();
stmt = db.conn.createStatement ();
rs = stmt.executeQuery(sqlStr);
allorder = new Vector();
while (rs.next()) {
order ind = new order();
ind.setId(rs.getLong("id"));
ind.setOrderId(rs.getString("orderId"));
ind.setUserId(rs.getLong("userid"));
ind.setSubmitTime(rs.getString("submitTime"));
ind.setConsignmentTime(rs.getString("ConsignmentTime"));
ind.setTotalPrice(rs.getFloat("TotalPrice"));
ind.setContent(rs.getString("content"));
ind.setIPAddress(rs.getString("IpAddress"));
if (rs.getInt("IsPayoff") == 1)
ind.setIsPayoff(false);
else
ind.setIsPayoff(true);
if (rs.getInt("IsSales") == 1)
ind.setIsSales(false);
else
ind.setIsSales(true);
allorder.addElement(ind);
}
rs.close();
return true;
}
catch (SQLException e) {
return false;
}
}
/**
* 查询书店的所有订单数据
* @return
*/
public boolean getOrder() {
sqlStr = "select count(*) from orders"; //取出记录数
int rscount = pageSize;
try {
DBConnection db = new DBConnection();
db.getConn();
stmt = db.conn.createStatement ();
ResultSet rs1 = stmt.executeQuery(sqlStr);
if (rs1.next())
recordCount = rs1.getInt(1);
rs1.close();
}
catch (SQLException e) {
return false;
}
//设定有多少pageCount
if (recordCount < 1)
pageCount = 0;
else
pageCount = (int) (recordCount - 1) / pageSize + 1;
//检查查看的页面数是否在范围内
if (page < 1)
page = 1;
else if (page > pageCount)
page = pageCount;
rscount = (int) recordCount % pageSize; // 最后一页记录数
//sql为倒序取值
sqlStr = "select * from orders ";
if (page == 1) {
sqlStr = sqlStr + " order by Id desc";
}
else {
sqlStr = sqlStr + " order by Id desc "/* limit */+(recordCount - pageSize * page) +","+ (recordCount - pageSize * (page - 1));
}
try {
DBConnection db = new DBConnection();
db.getConn();
stmt = db.conn.createStatement ();
rs = stmt.executeQuery(sqlStr);
allorder = new Vector();
while (rs.next()) {
order ind = new order();
ind.setId(rs.getLong("id"));
ind.setOrderId(rs.getString("orderid"));
ind.setUserId(rs.getLong("userid"));
ind.setSubmitTime(rs.getString("submitTime"));
ind.setConsignmentTime(rs.getString("ConsignmentTime"));
ind.setTotalPrice(rs.getFloat("TotalPrice"));
ind.setContent(rs.getString("content"));
ind.setIPAddress(rs.getString("IpAddress"));
if (rs.getInt("IsPayoff") == 1)
ind.setIsPayoff(false);
else
ind.setIsPayoff(true);
if (rs.getInt("IsSales") == 1)
ind.setIsSales(false);
else
ind.setIsSales(true);
allorder.addElement(ind);
}
rs.close();
return true;
}
catch (SQLException e) {
System.out.println(e);
return false;
}
}
/**
* 获得订单列表
* @param nid
* @return
*/
public boolean getAllorder(String order_id) {
sqlStr = "select * from allorder where orderId = '" + order_id + "'";
try {
DBConnection db = new DBConnection();
db.getConn();
stmt = db.conn.createStatement ();
rs = stmt.executeQuery(sqlStr);
order_list = new Vector();
while (rs.next()) {
allorder identlist = new allorder();
identlist.setId(rs.getLong("id"));
identlist.setOrderId(rs.getLong("orderId"));
identlist.setBookNo(rs.getLong("bookno"));
identlist.setAmount(rs.getInt("amount"));
order_list.addElement(identlist);
}
rs.close();
return true;
}
catch (SQLException e) {
System.out.print(e.getMessage());
return false;
}
}
各位大侠 这个异常信息表示出现了空指针 但是我不知道错在哪里 我贴出了部分相关程序
我看了几遍都觉得没问题 不知道错在哪里 怎么解决啊
[解决办法]
bookstoreonline.run.op_buy.payout(op_buy.java:320)
[解决办法]
public boolean payout 这个方法里面出现了空指针。
[解决办法]
up!!!1
[解决办法]
出现了栈满的情况,你检查一下是不是有死循环
[解决办法]
op_buy.java空指针异常
[解决办法]
这里:bookstoreonline.run.op_buy.payout(op_buy.java:320)出现了空指针异常,将鼠标点击:op_buy.java:320这里,可以看到你出现异常的代码。
[解决办法]
op_buy.java:320行代码是什么
[解决办法]
op_buy.java:320行代码有空指针
调试一下
祝楼主好运
[解决办法]
op_buy.java:320
看看 之前都有什么 ,报空指针异常的
------解决方案--------------------
op_buy 为空?
我的异常网推荐解决方案:The server encountered an internal error () that prevented it from fulfilling this request.,http://www.myexception.cn/java-web/317.html