增加响应缓冲区后收到以下错误:
SEVERE: Servlet.service() for servlet jsp threw exception java.lang.NullPointerException
at org.apache.jsp.redirects.redirects_005flist_jsp._jspService(redirects_005flist_jsp.java:325)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
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:230)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:581)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Unknown Source)
我在JSP中加入以下内容:
Welcome <%=userSession.getFirstName() %>!
由于用户会话为空,它应该重定向到登录页面,但它不是,当它到达上面一行时,它会抛出异常。
答案 0 :(得分:0)
我认为响应是在sendRedirect()
发生之前提交的。
答案 1 :(得分:0)
基本上,每次使用时都应该更换
resposnse.redirect("abc.jsp");
与
RequestDispatcher rd = request.getRequestDispatcher("abc.jsp");
rd.forward(request, response);
从您第一次在项目或会话
中使用它开始