JSP - 在表单进程上提供HTTP 500

时间:2014-05-22 17:56:01

标签: java html jsp tomcat nullpointerexception

我正在编写一个小的jsp文件来解析和验证用户输入。用于测试的html表单如下:

<html>
<head>
</head>
<body>
<form action="NewUser.jsp" method="POST">
<label for="usr">user name:</label>
<input type="text" name="usr"><br>
<label for="passwd">password:</label>
<input type="password" name="passwd">
<br>
<input type="submit" value="Sign Up">
</form>
</body>
</html>

接下来是JSP

<%@ page import="java.io.*" %>
<!DOCTYPE html>
<html>
<head>
<title>Registration Complete</title>
</head>
<body>
<%
    out.write(request.getParameter("user"));
    out.write(request.getParameter("passwd"));
%>
</body>
</html>

最后,我的错误:

HTTP Status 500 - java.lang.NullPointerException

--------------------------------------------------------------------------------

type Exception report

message java.lang.NullPointerException

description The server encountered an internal error that prevented it from fulfilling this request.

exception 

org.apache.jasper.JasperException: java.lang.NullPointerException
    org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:549)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:470)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)


root cause 

java.lang.NullPointerException
    java.io.Writer.write(Unknown Source)
    org.apache.jsp.NewUser_jsp._jspService(NewUser_jsp.java:72)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)


note The full stack trace of the root cause is available in the Apache Tomcat/7.0.47 logs.


--------------------------------------------------------------------------------

Apache Tomcat/7.0.47

我不明白。什么是null?我试图将方法更改为GET,但这不是解决方法。我的tomcat版本列在错误中。如果它有帮助,我的Tomcat就是通过Eclipse安装的。

1 个答案:

答案 0 :(得分:2)

您应该使用request.gerParameter(“usr”)而不是“user”。您的输入字段具有为第一个输入定义的字符串usr