Link to home
Start Free TrialLog in
Avatar of gudii9
gudii9Flag for United States of America

asked on

flush is Invalid for jsp:forward.. It is only valid for for jsp:include.

I was reading as follows

The attribute flush is  Invalid  for jsp:forward.. It is only valid for for jsp:include.

I have not understood its clear meanign and where we have to use flush and how, why.

please advise.
Any links resources, sample code, ideas highly appreciated. Thanks in advance
Avatar of rrz
rrz
Flag of United States of America image

If the flush method is called, then output is sent to the client and the response is committed. Once the response is committed, you can't forward to another resource because it needs to create it's own response. An include is allowed becauseit will only add to the current output to be sent to the client.
Avatar of gudii9

ASKER

>> An include is allowed becauseit will only add to the current output to be sent to the client.

Can you please elaborate on this.
The <jsp:include> action includes the response from another JSP page, Servlet or static file in the same web application. The execution of the current page continues after including the response generated by the target resource.  If any response content has been buffered when the <jsp:include> action is executed, the flush attribute controls whether or not to flush the buffer.
Avatar of gudii9

ASKER

>>If the flush method is called, then output is sent to the client and the response is committed. Once the response is committed, you can't forward to another resource because it needs to create it's own response



So for Forward order of execution of things are
1.response committed
2.output sent to client
3. flush method is called



>>>The <jsp:include> action includes the response from another JSP page, Servlet or static file in the same web application.The execution of the current page continues after including the response generated by the target resource.

In this case Target Resource means another JSP page, Servlet or static file in the same web application right?

What is the meaning of buffered. What is it relation, dependency with flush. can you please point me to any good simple example

Please advise
>So for Forward order of execution of things are  
I think you are incorrect in your last comment.  
A buffer is just a storage area. Read at
http://en.wikipedia.org/wiki/Data_buffer 
When flush is called that is what sends the contents of the buffer to the client. That commits the response.  
You should read  about buffering at
http://docs.oracle.com/javaee/1.4/api/javax/servlet/jsp/JspWriter.html 

The following  JSP works  
Text here will be put into buffer. 
But when I use  the forward this text will be cleared from the buffer and will not be sent to the client. 
<jsp:forward page="test.jsp" />  

Open in new window

 The following JSP produces error
<%@ page buffer="none" %>
When no buffer is used, this text will be sent to the client.
Now, when I try to forward, An error is thrown.
<jsp:forward page="test.jsp" />  

Open in new window

The error message from trying to use last code  is
java.lang.IllegalStateException: Illegal to clear() when buffer size == 0
Avatar of gudii9

ASKER

>>>Once the response is committed, you can't forward to another resource because it needs to create it's own response.


Can forward will be able to forward to another resource in other web application?(not in the same web application)


>>>The execution of the current page continues after including the response generated by the target resource.  If any response content has been buffered when the <jsp:include> action is executed, the flush attribute controls whether or not to flush the buffer.

>>>If any response content has been buffered


response content buffered by current page or target resource?

How response still buffers even after executing <jsp:include>
please advise
ASKER CERTIFIED SOLUTION
Avatar of rrz
rrz
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial