tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher Schultz <>
Subject Re: Servlets that use response.getOutputStream(): do they play nicely with Tomcat's error pages?
Date Fri, 01 May 2009 20:01:51 GMT
Hash: SHA1


On 4/29/2009 10:41 PM, Dave Cherkassky wrote:
> 1) I agree with you for includes and forwards, but for errors?  I would
> have thought that the definition of "error" is that something went
> wrong, and Tomcat should start from scratch and just render the error
> page.  I didn't think of it as really a forward...
> 2) So you are suggesting that writing out to the
> response.getOutputStream() as I go is wrong?  Instead, I need to:
> a. buffer my output locally
> b. once I am sure that it can all be created correctly, *then* I write
> out the buffer to the response?

The buffer isn't the problem, as Pid suggests. If it were, you'd be
getting a different error (something like "Response already committed").

The problem is that your servlet calls response.getOutputStream() and
your error page (a JSP) calls response.getWriter(). The servlet spec
says this is a no-no, so you get this exception thrown. It's not really
your fault per se, but that's what's happening.

Do you have the option of generating your Excel document to memory
(ByteArrayOutputStream) or a temporary file before streaming it to the
client? That would be ideal, as you could wait until the entire document
was generated before trying to send it (or any of the "Content-Type"
headers, which would be helpful). If an error occurs, the user gets an
error page instead of an error page disguised as an Excel document.

If the document you generate is huge, and you *must* stream it, well,
then, you just have to do a better job of error handling in your
servlet, then. Just catch Throwable or RuntimeException or whatever and
take appropriate action (whatever that means... maybe putting an error
directly in the Excel file like "OMG something bad happened... file

- -chris
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla -


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message