从传递电话号码的表单提交中获取 NumberFormat 异常。但是,传递的数字实际上是一个数字,我将其转换为 servlet 中的 int。在错误消息中,您可以看到在 - 8456640236 中输入了一个 int。
小服务程序方法
public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
Contact newComment = new Contact();
newComment.setName(request.getParameter("nameParameter"));
newComment.setEmail(request.getParameter("emailParameter"));
newComment.setPhone(Integer.parseInt(request.getParameter("phoneParameter")));
newComment.setComment(request.getParameter("commentParameter"));
request.setAttribute("commentAttribute", newComment);
RequestDispatcher view = request.getRequestDispatcher("/successComment.jsp");
view.forward(request, response);
}
错误信息
java.lang.NumberFormatException: For input string: "8456640236"
java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
java.lang.Integer.parseInt(Integer.java:461)
java.lang.Integer.parseInt(Integer.java:499)
org.test.Servlet.doPost(Servlet.java:21)
javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)