org.apache.jasper.JasperException:java.lang.NumberFormatException:在JSP页面上为null

时间:2019-03-01 14:02:03

标签: mysql jsp servlets error-handling

我收到此错误

  

org.apache.jasper.JasperException:java.lang.NumberFormatException:   空

当我运行JSP页面时,我不知道为什么。如果我尝试相同的代码而不在MySQL中插入整数,则效果很好。我已经解析了整数参数,所以不确定自己在做什么错。

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@page import="java.sql.*,java.util.*"%>
<!DOCTYPE html>
<html>
<body>
<form method="post" action="process.jsp">
Photo ID:<br>
<input type="text" name="p_ID">
<br>
Result:<br>
<input type="text" name="result">
<br>
Email:<br>
<input type="text" name="email">
<br>
<input type="submit" value="submit">
</form>
</body>

<%
int p_ID=Integer.parseInt(request.getParameter("p_ID"));
String result=request.getParameter("result");
String email=request.getParameter("email");


try
{
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/capture", "root", "");
Statement st=conn.createStatement();

int i=st.executeUpdate("insert into result(p_ID, result, email)values('"+p_ID+"','"+result+"','"+email+"')");
out.println("Data is successfully inserted!");
}
catch(Exception e)
{
System.out.print(e);
e.printStackTrace();
}
%> 

</html>

1 个答案:

答案 0 :(得分:0)

我认为在线发生问题

int i=st.executeUpdate("insert into result(p_ID, result, email)values('"+p_ID+"','"+result+"','"+email+"')");

在此行'"+p_ID+"'中,由于""p_ID成为字符串。因此,请从""中删除p_ID。因此,尝试将查询更改为

int i=st.executeUpdate("insert into result(p_ID, result, email)values('+p_ID+','"+result+"','"+email+"')");