Dave Cherkassky wrote:
> A long question:
>
> First, I have a Servlet that writes to response.getOutputStream().
> Here's a snippet:
> public class AuditTrailServlet extends HttpServlet {
> public void doGet( HttpServletRequest request, HttpServletResponse
> response )
> response.setContentType( "application/vnd.ms-excel" );
> response.setHeader( "Content-Disposition", "attachment; filename="
> + fileName );
>
> ResultSet rs = ...;
> for ( int row = 0 ; rs.next(); row++ ) {
> // iterate over each row in the ResultSet
> for( int col = 0; fieldNameIt.hasNext(); col++ ) {
> // iterate over each column in the results, write to spreadsheet
> // custom code.
> // let us assume this block has a bug that occasionally throws
> a NullPointerException, // but only after a bunch of cells are
> written first.
> response.getOutputStream().write( /* excel byte[] */ );
> // more custom code.
> }
> }
> rs.close();
>
> response.setStatus( HttpServletResponse.SC_OK );
> }
> }
>
> Second, I have the following in the web.xml file, to tell tomcat to use
> a custom error page:
> <error-page>
> <exception-type>java.lang.Throwable</exception-type>
> <location>/myError.jsp</location>
> </error-page>
>
> Last, here's myError.jsp:
> <%@ page isErrorPage='true' %>
> <html>
> <body>
> <h1>System Error</h1>
> <p>
> You have encountered a system error.
> </p>
>
> <%-- custom error processing that can't be done in a static .html page
> --%>
>
> </body>
> </html>
>
>
> So, it all seems standard and straight-forward, right?
>
>
>
> However, instead of seeing a nice custom error page when the NPE
> happens, I get the "ugly" Tomcat error page, and
> the following in the Tomcat logs:
> java.lang.IllegalStateException: getOutputStream() has already been
> called for this response
> at
> org.apache.catalina.connector.ResponseBase.getWriter(ResponseBase.java:709)
> at
> org.apache.catalina.connector.ResponseFacade.getWriter(ResponseFacade.java:127)
>
> at org.apache.jasper.runtime.JspWriterImpl.initOut(JspWriterImpl.java:128)
> at
> org.apache.jasper.runtime.JspWriterImpl.flushBuffer(JspWriterImpl.java:121)
> at
> org.apache.jasper.runtime.PageContextImpl.release(PageContextImpl.java:137)
> at
> org.apache.jasper.runtime.JspFactoryImpl.internalReleasePageContext(JspFactoryImpl.java:153)
>
> at
> org.apache.jasper.runtime.JspFactoryImpl.releasePageContext(JspFactoryImpl.java:148)
>
> at org.apache.jsp.error_jsp._jspService(error_jsp.java:284)
>
>
> Yes, I know -- I *am* using Tomcat 4.1 (rather than the latest and
> greatest) for various legacy and political reasons.
>
>
> But my question is this:
> - Is this a known bug? Or am I doing something wrong with either the
> servlet, the web.xml or with the jsp page?
I'm not sure it's a bug; logically, if you've sent a chunk of the
response (and therefore committed the response, sent headers etc)
*before* an exception happens how is Tomcat then supposed to tell the
client to stop and then display a different page?
p
> Thanks,
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]