tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From William Au <bi...@cnet.com>
Subject handling Exception from RequestDispatcher.include() in a JSP
Date Wed, 21 Mar 2001 22:50:59 GMT
I am about to give up on using multiple RequestDispatcher.forward() calls
or using include() then followed by a forward() in a JSP because I can't
make things work no matter what I try.

I guess I will have to use multiple include().  That seems to work as long
as there are no exceptions being thrown by the included JSPs.
When I catch an exception from an included JSP, I want to use
response.sendError() back to the client.  But I am getting the following
exception.

What the best way to handle exception thrown by included JSPs?

Bill
----------------------------------------------
Internal Servlet Error:

javax.servlet.ServletException: Response has already been committed
        at java.lang.Throwable.fillInStackTrace(Native Method)
        at java.lang.Throwable.fillInStackTrace(Compiled Code)
        at java.lang.Throwable.(Compiled Code)
        at java.lang.Exception.(Compiled Code)
        at javax.servlet.ServletException.(Compiled Code)
        at
org.apache.jasper.runtime.PageContextImpl.handlePageException(Compiled
Code)
        at
billa._0002fbilla_0002fcontroller_0002ejspcontroller_jsp_2._jspService(_0002fbilla_0002fcontroller_0002ejspcontroller_jsp_2.java:86)

        at org.apache.jasper.runtime.HttpJspBase.service(Compiled Code)
        at javax.servlet.http.HttpServlet.service(Compiled Code)
        at
org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(Compiled
Code)
        at org.apache.jasper.servlet.JspServlet.serviceJspFile(Compiled
Code)
        at org.apache.jasper.servlet.JspServlet.service(Compiled Code)
        at javax.servlet.http.HttpServlet.service(Compiled Code)
        at org.apache.tomcat.core.ServletWrapper.doService(Compiled Code)
        at org.apache.tomcat.core.Handler.service(Compiled Code)
        at org.apache.tomcat.core.ServletWrapper.service(Compiled Code)
        at org.apache.tomcat.core.ContextManager.internalService(Compiled
Code)
        at org.apache.tomcat.core.ContextManager.service(Compiled Code)
        at
org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(Compiled
Code)
        at org.apache.tomcat.service.TcpWorkerThread.runIt(Compiled Code)
        at org.apache.tomcat.util.ThreadPool$ControlRunnable.run(Compiled
Code)
        at java.lang.Thread.run(Compiled Code)

Root cause:

java.lang.IllegalStateException: Response has already been committed
        at java.lang.Throwable.fillInStackTrace(Native Method)
        at java.lang.Throwable.fillInStackTrace(Compiled Code)
        at java.lang.Throwable.(Compiled Code)
        at java.lang.Exception.(Compiled Code)
        at java.lang.RuntimeException.(Compiled Code)
        at java.lang.IllegalStateException.(IllegalStateException.java:45)
        at
org.apache.tomcat.facade.HttpServletResponseFacade.sendError(HttpServletResponseFacade.java:204)

        at
org.apache.tomcat.facade.HttpServletResponseFacade.sendError(HttpServletResponseFacade.java:196)

        at
billa._0002fbilla_0002fcontroller_0002ejspcontroller_jsp_2._jspService(_0002fbilla_0002fcontroller_0002ejspcontroller_jsp_2.java:65)

        at org.apache.jasper.runtime.HttpJspBase.service(Compiled Code)
        at javax.servlet.http.HttpServlet.service(Compiled Code)
        at
org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(Compiled
Code)
        at org.apache.jasper.servlet.JspServlet.serviceJspFile(Compiled
Code)
        at org.apache.jasper.servlet.JspServlet.service(Compiled Code)
        at javax.servlet.http.HttpServlet.service(Compiled Code)
        at org.apache.tomcat.core.ServletWrapper.doService(Compiled Code)
        at org.apache.tomcat.core.Handler.service(Compiled Code)
        at org.apache.tomcat.core.ServletWrapper.service(Compiled Code)
        at org.apache.tomcat.core.ContextManager.internalService(Compiled
Code)
        at org.apache.tomcat.core.ContextManager.service(Compiled Code)
        at
org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(Compiled
Code)
        at org.apache.tomcat.service.TcpWorkerThread.runIt(Compiled Code)
        at org.apache.tomcat.util.ThreadPool$ControlRunnable.run(Compiled
Code)
        at java.lang.Thread.run(Compiled Code)

> I am running Tomcat 3.2.1.
>
> I am getting the following error.
>
> javax.servlet.ServletException: Cannot forward as OutputStream or Writer
> has already been obtained
>
> My code is quite simple.  The jsp that I am including, example1.jsp,
> does not write anything to the
> output buffer.
>
> <%
> RequestDispatcher rd1 =
>   request.getRequestDispatcher("example1.jsp");
> rd1.include(request, response);
>
> RequestDispatcher rd2 =
>   request.getRequestDispatcher("example2.jsp");
> rd2.forward(request, response);
> %>
>
> The Apache Bug Database, bug #250, said this is fixed in 3.2.  Is there
> something
> wrong with my code?
>
> Bill


Mime
View raw message