0

I received the following error after increasing response buffer:

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)

I'm putting below line in the JSP:

Welcome <%=userSession.getFirstName() %>!

since the user session is null it should redirect to login page, but it is not and when it reaches the above line it is throwing exception.

Steven Benitez
  • 10,936
  • 3
  • 39
  • 50
Sinha
  • 773
  • 2
  • 16
  • 34

2 Answers2

0

I think the response is committed before the sendRedirect() happened.

Response committing might happen due to the reasons Causes for Response comitting

Community
  • 1
  • 1
Ramesh PVK
  • 15,200
  • 2
  • 46
  • 50
  • I increased the buffer size if the jsp but still getting the same error – Sinha Jul 03 '12 at 07:14
  • Increase the response buffer size also. Edited the link in my answer please check. – Ramesh PVK Jul 03 '12 at 07:26
  • How to increase response buffer size? – Sinha Jul 03 '12 at 07:31
  • ServletRespnse.setBufferSize(), the link in my answer explains this. – Ramesh PVK Jul 03 '12 at 07:43
  • if (userSession == null){ //response.sendRedirect("../login.jsp?currenturl=" + currentURL); response.setBufferSize(2000); response.sendRedirect("../login.jsp"); }and i'm getting above error(as edited)..I have no idea why it is coming out of the if block. – Sinha Jul 03 '12 at 09:19
  • sendRedirect() wont conclude the request/response. You need to return after that to prevent any code below that line from executing. – Steven Benitez Jul 03 '12 at 18:36
0

Basically you should replace every time you use

resposnse.redirect("abc.jsp");

with

RequestDispatcher rd = request.getRequestDispatcher("abc.jsp");
        rd.forward(request, response);

beginning from the first time you used it in the very project or session

StormeHawke
  • 5,987
  • 5
  • 45
  • 73