Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSP page strange Output

 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guys,

The code below from David Bridgewater's book,



The o/p,



Confused
 
Sergio Tridente
Ranch Hand
Posts: 329
Java Linux Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Interesting...

I took a quick look at the JspWriter class' javadocs. This is what I found:


The initial JspWriter object is associated with the PrintWriter object of the ServletResponse in a way that depends on whether the page is or is not buffered. If the page is not buffered, output written to this JspWriter object will be written through to the PrintWriter directly, which will be created if necessary by invoking the getWriter() method on the response object. But if the page is buffered, the PrintWriter object will not be created until the buffer is flushed and operations like setContentType() are legal. Since this flexibility simplifies programming substantially, buffering is the default for JSP pages.


I wonder what will happen if you call out.flush() explicitly. Most likely the output will show in the expeceted order.
 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sergio,

Any reason as to why the o/p was as shown above?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"out" is a very special object which works differently from response.getWriter(), described in "JSP.1.7 Overall Semantics of a JSP Page".

The "out" is being buffered, and won't be flushed until the buffer is full, or the page is done. "direct" here is a JspWriter which does not support buffering, so the output is immediate.

Try to add buffer="none" to your page directive, and see what the output is.
 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Satou,

I happen to understand it today. Thanks for the explanation!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic