org.apache.jasper.JasperException: An exception occurred processing JSP page /ReplyOk.jsp at line 7

org.apache.jasper.JasperException: An exception occurred processing JSP page /ReplyOk.jsp at line 7

【Reply.jsp】

 

<%@ page language="java" contentType="text/html; charset=gbk"
pageEncoding="gbk"%>
<%@ page import="java.sql.*"%>
<%
int id = Integer.parseInt(request.getParameter("id"));
int rootid = Integer.parseInt(request.getParameter("rootid"));
%>
<!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=gbk">
<title>Insert title here</title>
</head>
<body>

<element>
<form action="ReplyOk.jsp" method="post">

<table border="1">
<input type="hidden" name="id" value="<%=id%>">
<inptu type="hidden" name="rootid" value="<%=rootid%>">
<tr>
<td>
<input type="text" name="title" size="80">
</td>
</tr>
<tr>
<td>
<textarea cols="80" rows="12" name="cont"></textarea>
</td>
</tr>
<tr>
<td>
<input type="submit" value="提交">
</td>
</tr>

</table>
</form></element>


</body>
</html>

 


【ReplyOk.jsp】

 


<%@ page language="java" contentType="text/html; charset=gbk"
    pageEncoding="ISO-8859-1"%>
    <%@page import="java.sql.*" %>
<%
int id = Integer.parseInt(request.getParameter("id"));
int rootid = Integer.parseInt(request.getParameter("rootid"));
String title=request.getParameter("title");
String cont=request.getParameter("cont");

Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://localhost/bbs?user=root&password=root";
Connection conn = DriverManager.getConnection(url);

conn.setAutoCommit(false);

String sql="insert into article values(null,?,?,?,?,now(),0)";
PreparedStatement pstmt=conn.prepareStatement(sql);
Statement stmt=conn.createStatement();

pstmt.setInt(1,id);
pstmt.setInt(2,rootid);
pstmt.setString(3,title);
pstmt.setString(4,cont);
pstmt.executeUpdate();

stmt.executeUpdate("update article set isleaf=1 where id="+id);
conn.commit();
conn.setAutoCommit(true);
stmt.close();
pstmt.close();
conn.close();
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
ok
</body>
</html>

 

【错误提示】


org.apache.jasper.JasperException: An exception occurred processing JSP page /ReplyOk.jsp at line 7

4:
5: <%
6:  int id = Integer.parseInt(request.getParameter("id"));
7:  int rootid = Integer.parseInt(request.getParameter("rootid"));
8:  String title=request.getParameter("title");
9:  String cont=request.getParameter("cont");
10: 
取到了空值,NULL作为参数输入Integer.parseInt就会出错。

Copyright © 2007-2012 www.chuibin.com 六维论文网 版权所有