You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Jeremy Green <my...@jeremygreen.me.uk> on 2005/11/07 12:48:54 UTC

Cannot forward after response has been committed

I have a web application that shows a series of pages - each one 
containing a set of images. JSF commandButtons and actions are used to 
navigate between the pages. The images are generated by a Servlet, and 
take a while (hundreds of ms each) to generate and download.

If a page is submitted before all the images are downloaded, more often 
than not, a blank response is displayed and an IllegalStateException / 
ServletException (depending on whether Tomcat 5.5 or 5.0 is being used) is 
thrown with the message:

"Cannot forward after response has been committed."

The problem is made worse by a slow server, a fast connection to the 
server, and if the JSF page and images take a long time to generate.

Unfortunately, this makes the application unusable :-(.

I have created a JIRA entry for this bug, and give a simplified test case 
that demonstrates the problem (a single page containing a no-op 
commandButton and a graphicImage linked to a "SlowServlet"):

http://issues.apache.org/jira/browse/MYFACES-612

Has anyone else seen this problem? Does anyone have any ideas about how to 
work around it? How might I work out how to fix MyFaces?

As the stack traces in the JIRA entry show, the exception is thrown when 
the ViewHandler tries to dispatch the request to the JSP page to render 
the response. Perhaps something in MyFaces is flushing the FacesServlet 
output buffer prematurely? The size of the page in the test case is well 
below the 8k standard buffer size, but my understanding is that nothing 
should be written to the output buffer before the dispatch to the JSP 
page.

Jeremy

Re: Cannot forward after response has been committed

Posted by Jeremy Green <my...@jeremygreen.me.uk>.
On Mon, 7 Nov 2005, Tim Davies wrote:

> I had a similar problem, or at least sympton when I first started using 
> MyFaces. For me it was occurring as a result of redirects however. The 
> solution I found to the problem was to call the method 
> "FacesContext.getCurrentInstance().responseComplete()" after every time 
> that I sent a redirect. This solved the problem instantly.

When I said that my web application has a series of pages, I wasn't 
perhaps being as clear as I should have been - there's only one jsp file, 
and forward and back commandButtons are used to update a page property in 
the backing bean.

Anyway, the test case in the JIRA entry just consists of one page, its 
commandButton is not bound to any method, and the exception is thrown when 
MyFaces it calls ServletExternalContextImpl.dispatch to forward to the JSP 
page to render the response.

Jeremy

Re: Cannot forward after response has been committed

Posted by Tim Davies <ti...@ktsplc.com>.
I had a similar problem, or at least sympton when I first started using 
MyFaces.

For me it was occurring as a result of redirects however. The solution I 
found to the problem was to call the method 
"FacesContext.getCurrentInstance().responseComplete()" after every time 
that I sent a redirect. This solved the problem instantly.

The page I found that on, (cant remember where Im afraid), suggested 
that this was due to a current known bug in MyFaces.

I dont know if thats any help but good luck anyway.

T

(im on tomcat 5.5 and myfaces 1.1.1)


Jeremy Green wrote:

> I have a web application that shows a series of pages - each one 
> containing a set of images. JSF commandButtons and actions are used to 
> navigate between the pages. The images are generated by a Servlet, and 
> take a while (hundreds of ms each) to generate and download.
>
> If a page is submitted before all the images are downloaded, more 
> often than not, a blank response is displayed and an 
> IllegalStateException / ServletException (depending on whether Tomcat 
> 5.5 or 5.0 is being used) is thrown with the message:
>
> "Cannot forward after response has been committed."
>
> The problem is made worse by a slow server, a fast connection to the 
> server, and if the JSF page and images take a long time to generate.
>
> Unfortunately, this makes the application unusable :-(.
>
> I have created a JIRA entry for this bug, and give a simplified test 
> case that demonstrates the problem (a single page containing a no-op 
> commandButton and a graphicImage linked to a "SlowServlet"):
>
> http://issues.apache.org/jira/browse/MYFACES-612
>
> Has anyone else seen this problem? Does anyone have any ideas about 
> how to work around it? How might I work out how to fix MyFaces?
>
> As the stack traces in the JIRA entry show, the exception is thrown 
> when the ViewHandler tries to dispatch the request to the JSP page to 
> render the response. Perhaps something in MyFaces is flushing the 
> FacesServlet output buffer prematurely? The size of the page in the 
> test case is well below the 8k standard buffer size, but my 
> understanding is that nothing should be written to the output buffer 
> before the dispatch to the JSP page.
>
> Jeremy


-- 
Tim Davies
Analyst Developer

KTS PLC: Service you can bank on
8th Floor, Finsbury Tower,
103-105 Bunhill Row,
London  EC1Y 8TY
tel: +44 (0)20 7256 2300
fax: +44 (0)20 7256 2301

email: tim.davies@ktsplc.com
web: http://www.ktsplc.com