I am trying to catch all errors from my JSP, but I have found a problem with Jakarta-Tomcat that it is not on OrionServer. I have two jsp: jsp1 and jsp2. jsp1 includes jsp2, and then jsp2 throws an error. I am using tomcat 3.2B3 on windows 2000 with jdk 1.3. I have tested the same with orionserver and it works fine. On this mail I send the error thrown and the three jsp pages: jsp1.jsp, jsp2.jsp and errorPage.jsp. When I run http://localhost/mycontext/jsp1.jsp I get the following error: This is the content from jsp1 before inserting jsp2 -------------------------------------------------------------------------------- Included servlet error: 500 Localizacion:/isum/jsp1.jsp Error interno del servlet: java.lang.IllegalStateException: Cannot forward as OutputStream or Writer has already been obtained at org.apache.tomcat.facade.RequestDispatcherImpl.forward(RequestDispatcherImpl.java:150) at org.apache.jasper.runtime.PageContextImpl.forward(PageContextImpl.java:414) at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:438) at _0002fjsp_00032_0002ejspjsp2_jsp_5._jspService(_0002fjsp_00032_0002ejspjsp2_jsp_5.java:70) at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:119) at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:177) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:296) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:369) at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:368) at org.apache.tomcat.core.Handler.service(Handler.java:261) at org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:356) at org.apache.tomcat.facade.RequestDispatcherImpl.include(RequestDispatcherImpl.java:308) at org.apache.jasper.runtime.PageContextImpl.include(PageContextImpl.java:407) at _0002fjsp_00031_0002ejspjsp1_jsp_5._jspService(_0002fjsp_00031_0002ejspjsp1_jsp_5.java:69) at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:119) at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:177) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:296) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:369) at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:368) at org.apache.tomcat.core.Handler.service(Handler.java:261) at org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:356) at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:720) at org.apache.tomcat.core.ContextManager.service(ContextManager.java:666) at org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(HttpConnectionHandler.java:194) at org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:403) at org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:498) at java.lang.Thread.run(Unknown Source) -------------------------------------------------------------------------------- This is the content from jsp1 after inserting jsp2 ---------- jsp1.jsp---------- <%@ page errorPage="/errorPage.jsp" %> <html> <head><title>JSP Page</title></head> <body> <% out.println("This is the content from jsp1 before inserting jsp2"); %> <hr> <jsp:include page="jsp2.jsp" flush="true"/> <hr> <% out.println("This is the content from jsp1 after inserting jsp2"); %> </body> </html> ------------------------------ ---------- jsp2.jsp---------- <%@ page errorPage="errorPage.jsp" %> <% out.println("Lets throw an exception:....."); if (true) throw new Exception("Oops an Error has occurred"); %> ------------------------------ ---------- errorPage.jsp---------- <%@ page isErrorPage="true" import="java.io.*,com.tissat.isum.util.Util" %> <html> <head><title>JSP Page</title></head> <body> Something bad has happened. And it looks like: <br> <%= "Exception "+ exception %> <br><br> <%= "Message " + exception.getMessage() %> <% Util.error(exception.toString()); //exception.printStackTrace(); %> <br> </body> </html> -------------------------------------- How could this be solved? Has this already reported as a bug?
This works fine in 3.2.2b1. It must have been fixed and the bug report never closed.
Actually, I wonder that it is actually fixed.... The JSP include is supposed to flush the jsp doing the include into the response stream. Once flushed, an error should cause indeterminate output - the engine should not be able to write a completely separate errorpage to the response stream given that the first part of the original page has already been flushed!