Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Response commitment for buffered and unbuffered pages

Aniket Patil
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The JSP specification says:

Data is sent to the response stream on buffer flushes for buffered pages, or on encountering the first content (beware of whitespace) on unbuffered pages.

In the following code:

I am setting the buffer size to 0, which should be equivalent to an unbuffered page. Next i try to print "This is the right code " to the browser, which acc. to the spec statement above, should be flushed immediately on encountering the first println() for unbuffered pages. After that, i attempt to forward to result.jsp.

There is no IllegalStateException thrown, not even in console, even though i am trying to forward after committing the response. Secondly, instead of "This is the right code " getting printed to the browser (since the page is unbuffered), the browser gets forwarded to result.jsp, which is unexpected. With an out.flush(), "This is the right code " gets printed, but a flush() shouldn't be necc for unbuffered pages.

Please clarify when a response gets committed and why the code above exhibits such behavior.

[ March 13, 2007: Message edited by: Aniket Patil ]
[ March 13, 2007: Message edited by: Aniket Patil ]
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!