问答详情
源自:1-14 阶段案例

我的页面跳转,登陆失败可以跳转,登陆成功无法跳转,显示错误如下

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:556)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:477)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)


root cause

java.lang.NullPointerException
org.apache.jsp.login_005fsuccess_jsp._jspService(login_005fsuccess_jsp.java:116)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:439)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)


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

下面的是我的ServletLogin里的部分代码

public void doPost(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {

Users u = new Users();

String username = request.getParameter("username");

String password = request.getParameter("password");

u.setUsername(username);

u.setPassword(password);

if(u.getUsername().equals("admin")&&u.getPassword().equals("admin")){

response.sendRedirect(request.getContextPath()+"/login_success.jsp");

}else{

response.sendRedirect(request.getContextPath()+"/login_failure.jsp");

}

}


提问者:终有弱水替沧海4032800 2016-11-18 21:16

个回答

  • 慕粉3349069
    2016-11-19 06:20:43
    已采纳

    你可以打断点java单步调试一下,可以简单先分析一下:你报500错误,是内部错误,也就是你访问servlet错误,原因是

    type Exception report

    message java.lang.NullPointerException

    root cause

    java.lang.NullPointerException

    空指针异常。

    看你部分代码

    String username = request.getParameter("username");

    String password = request.getParameter("password");

    这两句最有可能是异常所发生地方,如果是,你可以检查一下,jsp页面的用户名的name属性和用户名的密码属性,是否是username和password;如果不是,请你单步调试,精准找到报错代码,再解决。