做数据库的更新操作时,出的这个问题:以下是问题描述
org.apache.jasper.JasperException: null
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:372)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
root cause
java.lang.NumberFormatException: null
java.lang.Integer.parseInt(Integer.java:436)
java.lang.Integer.parseInt(Integer.java:518)
org.apache.jsp.update_jsp._jspService(update_jsp.java:62)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
以下是我写的数据库更新JSP:
<%@ page contentType="text/html; charset=GB2312" language="java" import="java.sql.*" errorPage="" %>
<%@ page import="javax.naming.*,javax.sql.*"%>
<!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>
<%
request.setCharacterEncoding("GB2312");
String bookName = request.getParameter("bookName");
String publisher = request.getParameter("publisher");
String price = request.getParameter("price");
String stringupId = request.getParameter("upId");
int upid = Integer.parseInt(stringupId);
if(null==bookName||null==publisher||null==price){
response.sendRedirect("bookupdate.jsp");
}
if("".equals(bookName)||"".equals(publisher)){
response.sendRedirect("bookupdate.jsp");
}
Context context = new InitialContext();
DataSource ds =(DataSource)context.lookup("java:comp/env/jdbc/testSql");
Connection con = ds.getConnection();
PreparedStatement ps = con.prepareStatement("update book set bookName=?,publisher=?,price=? where bookId=?");
ps.setString(1,bookName);
ps.setString(2,publisher);
ps.setString(3,price);
ps.setInt(4,upid);
ps.executeUpdate();
out.println("更新成功");
//response.sendRedirect("bookShow.jsp");
ps.close();
con.close();
%>
</body>
</html>
------解决方法--------------------------------------------------------
强制转换出错.那里的Integer转换出错,你仔细看看
------解决方法--------------------------------------------------------
int upid = Integer.parseInt(stringupId);
上面这句中的stringupId是null
自己检查一下为什么值没有传过来吧
------解决方法--------------------------------------------------------
虽然传过来了,但是包含非数字字符
------解决方法--------------------------------------------------------
String stringupId = (String)session.getAttribute("updataId");
DataSource ds =(DataSource)context.lookup("java:comp/env/jdbc/testSql");
上面的两句中某句产生了类型转换错误。
比如第一句,session.getAttribute("updataId")返回的可能不是String类型
好好检查一下它们的类型是否匹配