tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alex Cruikshank <>
Subject Re: [PATCH] JspWriter "... already been flushed" Error if pagethrows exception after 8192 bytes
Date Sat, 11 Dec 1999 00:42:40 GMT
After going through the code some more, I see what you mean.  It's not 
enough to ignore the error in PageContextImpl, because, if someone has set 
up an errorPage, the page will call context.forward() to display the 
errorPage and the RequestDispatcher will (rightly) throw an 
IllegalStateException.  The PageContext.forward throws the 
IllegalStateException, because it can't forward after data has been sent to 
the browser (in the default case, after 8192 characters).

Unfortunately, this seems to be part of a much larger problem with 
jsp:forward.  The fact that PageContext.forward must throw an 
IllegalStateException if data has been sent to the browser means that it 
can only be safely used before the first character is sent, because the 
number of characters that may be written to the JspWriter without sending 
data to the screen is defined by the users configuration.

It makes me wonder it Jsp should really have a forward command, even though 
it can be extremely useful.  I can't imagine anyway, aside from creating an 
arbitrarily large buffer, that the forward can be expected to work 

The only fix I can think of for error handling would be to somehow check 
the state of out before trying to clear() and forward().  If data has been 
sent to the client, maybe it should print a benign message and put the 
stack trace  in html comments.  What else can you do?

- alex

>That is clearly a bug that needs to be corrected, but I'm afraid your
>solution is not the right one (see below).
> > Run the jsp attached file.  If you remove the last "1" in the last
> > out.print() statement (or any other number) it works as expected.  There
> > are exactly 8192 numbers that get printed to the writer.
> >
> > CAUSE:
> > When an exception is thrown within a Jsp page, the JspWriter's clear()
> > method is called before the exception is handled.  The clear() method in
> > JspWriterImpl checks to see if the "flushed" variable is true, and throws
> > an exception if it has (I'm not sure why).  [...]
>Without studying the code, I assume the flushed flag is there to throw
>exceptions when you try to do things, like clear(), that can not be done
>once some content has been sent to the client. So resetting it is not the
>solution. A better solution may be to ignore the exception in the 
>page exception handling code.

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message