简单BBS jsp提交回复页面报这个异常,没分了求好心人帮下

有猿千里来相会 2011-11-07 01:46:08
这是我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"));
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=admin";
Connection conn = DriverManager.getConnection(url);


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

conn.setAutoCommit(false);

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();
%>
<!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>
<font>
k
</font>
</body>
</html>

异常是:严重: Servlet.service() for servlet jsp threw exception
java.lang.NumberFormatException: For input string: "id"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
...全文
59 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
我在肖申克 2011-11-09
  • 打赏
  • 举报
回复
前台传递过来的ID 不是数字类型 或者 带有空格 而后台未作校验
  • 打赏
  • 举报
回复
我加了个try{}catch 不报错了。。但是回复的内容提交不到mysql数据库里。。是空的。。
  • 打赏
  • 举报
回复
NumberFormatException: For input string: "id"

把这个输出来看看,是不是非法数字

request.getParameter("id");

NumberFormatException.java:48

23,409

社区成员

发帖
与我相关
我的任务
社区描述
Java 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧