Solved

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

Posted on 2013-01-25
7
574 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
How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

Suggested Solutions

Title # Comments Views Activity
configure dependency in POM for new database 3 33
arguments to jar 5 33
tomcat startup error 5 100
maven disable workspace resolution 1 15
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
I had a project requirement for a displaying a user workbench .This workbench would consist multiple data grids .In each grid the user will be able to see a large number of data. These data grids should allow the user to 1. Sort 2. Export the …
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

789 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