• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Regarding out.flush() in <jsp:include> and <jsp:forward>

 
Chinmaya Chowdary
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, if I call,
the output is Welcome to our page. After calling the out.flush(), the container sends "Welcome to our page" as the response.
But if I call, the container will not commits "Welcome to our page" as the response. Can you please tell me, why the container commits the response if we call <% out.flush(); %> incase of <jsp:forward> and not incase of <jsp:include>. What exactly is"out.flush()".Thankyou.
 
Ankit Garg
Sheriff
Posts: 9577
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In both the cases the container will flush the output to the client. What makes you think that it doesn't do that in the case of include?? In the case of forward, the forward throws an Exception as the output has been sent to the client so there is no further result thus the browser renders it straight away. In the case of include, there is further response so the browser may not render it straight away (I'm saying this if you have used a Thread.sleep in the included jsp to see the behavior)...
 
Chinmaya Chowdary
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply. Incase of <jsp:forward> after out.flush(), the container throws an IllegalStateException. But incase of <jsp:include> it seems, the container will not throw IllegalStateException, thats why, we are able to see the output from both the jsp's(one included one and the including one). My question is, if it is so, why the container is not throwing IllegalStateException in case of <jsp:include>. Please clarify. Thankyou.
 
Vishwanath Krishnamurthi
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When the out.flush() happens, the response is comitted. That is, the buffer content at the moment is sent. And after that content is 'sent' if you try to change the 'sent content' by using a redirect or a forward then you get the IllegalStateException.

But when you do:

// contentA
out.flush(); //contentA is 'sent' from the buffer
//contentB
out.flush(); //contentB is 'sent' from the buffer

its not gaonna throw a problem because all you are doing is sending contents from the buffer in batches but you are not trying in anyway to affect what was already sent.

Same applies to

//contentA
out.flush();
<jsp:include...>
out.flush();

HTH,
Vishwa
 
Chinmaya Chowdary
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thankyou Sir, for your help on usage of out.flush();
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic