当前位置: 代码迷 >> Java Web开发 >> 跳转出错,该如何处理
  详细解决方案

跳转出错,该如何处理

热度:3159   发布时间:2013-02-25 21:20:35
跳转出错
我登录第一次后进行重新选购物品,跳转出错 public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

response.setContentType("text/html");
response.setCharacterEncoding("utf-8");
PrintWriter out = response.getWriter();

UserBean ub=(UserBean)request.getSession().getAttribute("userinfo");
if (ub==null) {
request.getRequestDispatcher("login.jsp").forward(request, response);
} else {
request.getRequestDispatcher("userAndMycar.jsp").forward(request, response);这行出错,不能进行跳转
}

}后台异常如下:
java.lang.NullPointerException
at org.apache.jsp.userAndMycar_jsp._jspService(userAndMycar_jsp.java:173)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:646)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:436)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:374)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:302)
at lwl.servlet.isLoginServlet.doGet(isLoginServlet.java:36)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:619)
2012-5-9 10:43:05 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet isLoginServlet threw exception

------解决方案--------------------------------------------------------
空指针异常
at lwl.servlet.isLoginServlet.doGet(isLoginServlet.java:36)

getAttribute改成getParameter试试

------解决方案--------------------------------------------------------
楼主应该把完整代码贴出来,也许是由其他地方的错误引起的……
------解决方案--------------------------------------------------------
UserBean ub=(UserBean)request.getSession().getAttribute("userinfo");
有没有userinfo这个对象?
------解决方案--------------------------------------------------------
if (ub==null) {
改成
if (null==ub) {
试一试



------解决方案--------------------------------------------------------
本站暂不开放注册!
内测阶段只得通过邀请码进行注册!