What is the rationale for this exception on forwarding of the request. The reason behind the exception on response.redirect is that a 30x redirect response header can’t be issued after some of the response body has been flushed to the output stream. But I don’t see the reason for doing this on an internal forward.
The use case I have in mind is to early flush the html content from filters so the browser can get a head start (pun intended) on the top css and javascript while the servlet does its backend work before handing off to a presentation jsp. By yielding the first byte sooner, I’m hoping to see a client side performance benefit.
Struts and other frameworks depend on forward dispatches. It is because of these forwards that we can’t flush response content early, according to the API.
http://download.oracle.com/javaee/6/api/javax/servlet/RequestDispatcher.html#forward(javax.servlet.ServletRequest, javax.servlet.ServletResponse)
Because, imagine the case when you send some
<head>definitions to the browser, and then forward to a page that is completely different. The result will be some messed-up page. With (perhaps) two<head>sections, one of which is irrelevant.You can use
requestDispatcher.include(..)in order to include the result of a different page, rather than forward to it.