You are viewing a plain text version of this content. The canonical link for it is here.
Posted to taglibs-user@tomcat.apache.org by Stefan Håkans <st...@ibfs.com> on 2000/12/15 14:27:22 UTC

JspWriter problems

Hello!
I get this exception's stacktrace output by Tomcat3.1 on my page

"java.lang.IllegalStateException: Cannot forward as OutputStream or Writer
has already been obtained."

why is that?!
I have several custom tags on the page.
some are extending BodyTagSupport and some are implementing Tag

The bodytags use this to output:
	bodyContent.writeOut(bodyContent.getEnclosingWriter());

and the non bodytags use:
	JspWriter out = pageContext.getOut();
	out.write("...");

/Stefan




Stefan Håkans
I n t e r b i z z   S c a n d i n a v i a  a b
mailto:stefan.hakans@interbizz.se
http://www.interbizz.com



Re: JspWriter problems

Posted by Su Gao <an...@newmail.net>.
When you throw an exception, the page acutally call forward method to forward
the request to the error page. A forward method will try to clear all output,
if you alread flushed it, the exception will be thrown. I suppose you have used
<jsp:include> tag before the forward action is excuted, the include action will
flush output. So, check your code, if there is any include tag, try to change
them as static include <%@ include %>, or you have to give up the error page
method.

hope helps

Stefan H�kans wrote:

> I'm not flushing. I'm trying to throw a new JspException but instead of
> going to the errorpage the IllegalStateException occurs.
>
> Stefan
>
> -----Original Message-----
> From: chris [mailto:chris]On Behalf Of Chris Widhelm
> Sent: den 15 december 2000 16:09
> To: taglibs-user@jakarta.apache.org
> Subject: Re: JspWriter problems
>
> Stefan,
>
> Are you flushing any of your response outputs?
>
> You will get the IllegalStateException if you are doing that and then
> trying to access the response to do something like a forward.
>
> Chris
>
> Stefan H�kans wrote:
> >
> > Hello!
> > I get this exception's stacktrace output by Tomcat3.1 on my page
> >
> > "java.lang.IllegalStateException: Cannot forward as OutputStream or Writer
> > has already been obtained."
> >
> > why is that?!
> > I have several custom tags on the page.
> > some are extending BodyTagSupport and some are implementing Tag
> >
> > The bodytags use this to output:
> >         bodyContent.writeOut(bodyContent.getEnclosingWriter());
> >
> > and the non bodytags use:
> >         JspWriter out = pageContext.getOut();
> >         out.write("...");
> >
> > /Stefan
> >
> > Stefan H�kans
> > I n t e r b i z z   S c a n d i n a v i a  a b
> > mailto:stefan.hakans@interbizz.se
> > http://www.interbizz.com


RE: JspWriter problems

Posted by Stefan Håkans <st...@ibfs.com>.
I'm not flushing. I'm trying to throw a new JspException but instead of
going to the errorpage the IllegalStateException occurs.

Stefan

-----Original Message-----
From: chris [mailto:chris]On Behalf Of Chris Widhelm
Sent: den 15 december 2000 16:09
To: taglibs-user@jakarta.apache.org
Subject: Re: JspWriter problems


Stefan,

Are you flushing any of your response outputs?

You will get the IllegalStateException if you are doing that and then
trying to access the response to do something like a forward.

Chris

Stefan Håkans wrote:
>
> Hello!
> I get this exception's stacktrace output by Tomcat3.1 on my page
>
> "java.lang.IllegalStateException: Cannot forward as OutputStream or Writer
> has already been obtained."
>
> why is that?!
> I have several custom tags on the page.
> some are extending BodyTagSupport and some are implementing Tag
>
> The bodytags use this to output:
>         bodyContent.writeOut(bodyContent.getEnclosingWriter());
>
> and the non bodytags use:
>         JspWriter out = pageContext.getOut();
>         out.write("...");
>
> /Stefan
>
> Stefan Håkans
> I n t e r b i z z   S c a n d i n a v i a  a b
> mailto:stefan.hakans@interbizz.se
> http://www.interbizz.com


Re: JspWriter problems

Posted by Chris Widhelm <cw...@arcmail.com>.
Stefan,

Are you flushing any of your response outputs?

You will get the IllegalStateException if you are doing that and then
trying to access the response to do something like a forward.

Chris

Stefan Håkans wrote:
> 
> Hello!
> I get this exception's stacktrace output by Tomcat3.1 on my page
> 
> "java.lang.IllegalStateException: Cannot forward as OutputStream or Writer
> has already been obtained."
> 
> why is that?!
> I have several custom tags on the page.
> some are extending BodyTagSupport and some are implementing Tag
> 
> The bodytags use this to output:
>         bodyContent.writeOut(bodyContent.getEnclosingWriter());
> 
> and the non bodytags use:
>         JspWriter out = pageContext.getOut();
>         out.write("...");
> 
> /Stefan
> 
> Stefan Håkans
> I n t e r b i z z   S c a n d i n a v i a  a b
> mailto:stefan.hakans@interbizz.se
> http://www.interbizz.com