• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JspWriter out (page 251 Charles Lyons)

 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

This is from book (Charles Lyons) Page 251:


Out(JspWriter)
An output stream which buffers between the page and the response stream. In
properties (such as buffer size and flush control) can be configured in the
page directive. Your JSP scripting elements should always write to the
out object and not directly to the response stream.



I am not getting the lines (I have made in bold face).
Please help me to understand this.


Thanks,
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use response.getOutputStream or response.getWriter, but you must not use them, and use "out" object instead. (I think that you'd get an IllegalStateException if you try to)
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Christophe!

Does this mean, we should not first acquire output stream using
response.getOutputStream() or response.getWriter() to write on the
response. We should always use out implicit object for this purpose.
Because if we do either, IllegalStateException will occur, because we
can't another if the second on has already been acquired.

BUT:
It is also true that, template text of jsp goes inside out.write()
and expression inside the out.println(). How is this managed?

Please clear my doubts.


Thanks,
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is also true that, template text of jsp goes inside out.write()
and expression inside the out.println(). How is this managed?

The translated JSP gets it from JspContext.getOut() method. It declares a member variable called "out", and sets its value to getOut(). That's the same "out" you are using in your JSP.
 
subodh gupta
Ranch Hand
Posts: 203
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

What is said on these lines means you should use buffered output and not directly write to output stream. And since JspWritter handles that for us its better to use out object of (JspWritter).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic