Solved

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

Posted on 2013-01-25
7
563 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 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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:
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

920 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now