Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2013-01-25
7
Medium Priority
?
607 Views
Last Modified: 2013-02-17
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
0
Comment
Question by:gudii9
  • 4
  • 3
7 Comments
 
LVL 28

Expert Comment

by:rrz
ID: 38841262
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.
0
 
LVL 7

Author Comment

by:gudii9
ID: 38844719
>> An include is allowed becauseit will only add to the current output to be sent to the client.

Can you please elaborate on this.
0
 
LVL 28

Expert Comment

by:rrz
ID: 38845121
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.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 7

Author Comment

by:gudii9
ID: 38856159
>>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
0
 
LVL 28

Expert Comment

by:rrz
ID: 38856734
>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
0
 
LVL 7

Author Comment

by:gudii9
ID: 38873390
>>>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
0
 
LVL 28

Accepted Solution

by:
rrz earned 2000 total points
ID: 38889539
>Can forward will be able to forward to another resource in other web application?(not in the same web application)  
No
>response content buffered by current page or target resource?    
current page  
>How response still buffers even after executing <jsp:include>    
The response is buffered until the end of page is reached or until the buffer overflows.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses

927 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question