当前位置: 代码迷 >> J2EE >> java.lang.NumberFormatException: null 异常
  详细解决方案

java.lang.NumberFormatException: null 异常

热度:101   发布时间:2016-04-22 01:29:44.0
java.lang.NumberFormatException: null 错误
org.apache.jasper.JasperException: An exception occurred processing JSP page /ReplyOK.jsp at line 5

2: pageEncoding="UTF-8"%>
3: <%@ page import="java.sql.*" %>
4: <%
5: int id = Integer.parseInt(request.getParameter("id"));
6: int rootId = Integer.parseInt(request.getParameter("rootid"));
7: 
8: String title = request.getParameter("title");

  
我的源代码
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();

------解决方案--------------------
根据错误信息提示,应该是request.getParameter("id")返回null了,LZ好好查看一下是不是值能正常取到了
------解决方案--------------------
探讨

根据错误信息提示,应该是request.getParameter("id")返回null了,LZ好好查看一下是不是值能正常取到了

代码迷推荐解决方案:An exception occurred processing JSP page,http://www.daimami.com/search?q=33144
  相关解决方案