Solved

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

Posted on 2013-01-25
7
585 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 27

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 27

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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
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 27

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 27

Accepted Solution

by:
rrz earned 500 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

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

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

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
In this post we will learn different types of Android Layout and some basics of an Android App.
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…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Suggested Courses

627 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