• Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Chinmaya Chowdary
Ranch Hand
Posts: 437
  • 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.
 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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>.


There is no difference between them..how did you arrive to this ?
 
Chinmaya Chowdary
Ranch Hand
Posts: 437
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply. If we call out.flush() before <jsp:forward />, the thing before out.flush() will be be committed.(it clears the buffer) And the container sees the <jsp:forward/>, since it has committed the response, the container throws an IllegalStateException(that we cann't see, since the response has already committed). But incase of <jsp:include/>, it will not happen.In this case, the container, clears the buffer before out.flush(), and it sees <jsp:include/>, it will not throw an exception, it will be executed normally. My question is, why it is throwing exception incase of <jsp:forward/>? What exactly is out.flush()? Thankyou.
 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Its not the out.flush which behaves differently for forward and include. It lies with jsp:include and jsp:forward. To put it simply, jsp:include includes the response to the "same" outout stream , whereas jsp:forward , will actually close the opened outputstream. before forward.

So now you see include will ultimately give a single response for you request , where as if you flush out and forward , you are trying to provide 2 responses to a single request. this is not allowed. you do not want that either.
Its the design decision whether you include or forward. you use forward when you want output from different jsp file .
 
Chinmaya Chowdary
Ranch Hand
Posts: 437
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thankyou Sir.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!