response.sendRedirect Query

Discussion in 'Java' started by parkarumesh@gmail.com, Jun 1, 2006.

  1. Guest

    Hi

    The following code snippet is a funtion in my servlet.

    public static void errorHandling(int code)
    {
    try{
    String forwardString = "/parser/errorPage.jsp?errorCode="+code;
    System.out.println("****FORWARD STRING: "+forwardString);

    response.sendRedirect(forwardString);
    return;

    /*RequestDispatcher disp =
    request.getRequestDispatcher(forwardString);
    disp.forward(request,response);*/

    //response.resetBuffer();
    //response.flushBuffer();
    /*if(!response.isCommitted())
    response.flushBuffer();*/

    }catch(Exception ex){ex.printStackTrace();}
    }

    }

    Here response and request are static.

    Now when i call this function from a normal class it executes fine.
    However if i call it from a jsp no mesaage is displyed and the foll
    exception is thrown.

    java.lang.NullPointerException
    at
    org.apache.coyote.tomcat4.CoyoteResponseFacade.isCommitted(CoyoteRes
    onseFacade.java:242)
    at
    org.apache.coyote.tomcat4.CoyoteResponseFacade.sendRedirect(CoyoteRe
    ponseFacade.java:337)
    at parserPckg.ReadDate.errorHandling(ReadDate.java:79)
    at
    org.apache.jsp.FolderActivity_jsp._jspService(FolderActivity_jsp.jav
    :101)
    at
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:137)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
    at
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrappe
    ..java:210)
    at
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:
    95)
    at
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
    at
    org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(App
    icationFilterChain.java:247)
    at
    org.apache.catalina.core.ApplicationFilterChain.doFilter(Application
    ilterChain.java:193)
    at
    org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapper
    alve.java:256)
    at
    org.apache.catalina.core.StandardPipeline$StandardPipelineValveConte
    t.invokeNext(StandardPipeline.java:643)
    at
    org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.ja
    a:480)
    at
    org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995

    at
    org.apache.catalina.core.StandardContextValve.invoke(StandardContext
    alve.java:191)
    at
    org.apache.catalina.core.StandardPipeline$StandardPipelineValveConte
    t.invokeNext(StandardPipeline.java:643)
    at
    org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.ja
    a:480)
    at
    org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995

    at
    org.apache.catalina.core.StandardContext.invoke(StandardContext.java
    2417)
    at
    org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.
    ava:180)
    at
    org.apache.catalina.core.StandardPipeline$StandardPipelineValveConte
    t.invokeNext(StandardPipeline.java:643)
    at
    org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatch
    rValve.java:171)
    at
    org.apache.catalina.core.StandardPipeline$StandardPipelineValveConte
    t.invokeNext(StandardPipeline.java:641)
    at
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.
    ava:172)
    at
    org.apache.catalina.core.StandardPipeline$StandardPipelineValveConte
    t.invokeNext(StandardPipeline.java:641)
    at
    org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.ja
    a:480)
    at
    org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995

    at
    org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVa
    ve.java:174)
    at
    org.apache.catalina.core.StandardPipeline$StandardPipelineValveConte
    t.invokeNext(StandardPipeline.java:643)
    at
    org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.ja
    a:480)
    at
    org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995

    at
    org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:1
    3)
    at
    org.apache.coyote.http11.Http11Processor.process(Http11Processor.jav
    :781)
    at
    org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.proc
    ssConnection(Http11Protocol.java:549)
    at
    org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.jav
    :589)
    at
    org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(Thread
    ool.java:666)
    at java.lang.Thread.run(Thread.java:534)

    Also attached the errorPage.jsp

    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html;
    charsekt=ISO-8859-1">
    <title>Error Page-You will be redirected to the previous page</title>
    </head>
    <body>
    <%
    int errorCode = Integer.parseInt(request.getParameter("errorCode"));
    System.out.println("****ERRORCODE: "+errorCode);
    switch(errorCode)
    {
    case 1: out.println("No activity in within specified dates");%>
    <a href="/parser/index.jsp">Back to Index</a>

    <%break;

    case 2: out.println("No activity in this folder");%>
    <a href="/parser/ActivityList.jsp">Back to Index</a>

    <%break;

    }
    %>
    </body>
    </html>

    Plz help
    , Jun 1, 2006
    #1
    1. Advertising

  2. chris brat Guest

    Check that your expected "errorCode" does actually exist in the request
    - a redirect creates a new request and all previously existing state
    data (your "errorCode" in this case is lost).

    To maintain state in the request rather use a forward or if the session
    if it is necessary.
    chris brat, Jun 2, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andreas
    Replies:
    6
    Views:
    3,209
    Andrea Desole
    Feb 15, 2005
  2. carlisle411
    Replies:
    4
    Views:
    12,280
    John C. Bollinger
    Feb 28, 2005
  3. Jeano
    Replies:
    5
    Views:
    7,236
    Orilg
    Oct 13, 2010
  4. ohaya
    Replies:
    0
    Views:
    4,080
    ohaya
    Jun 30, 2005
  5. Replies:
    0
    Views:
    1,193
Loading...

Share This Page