• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JspWriter out (page 251 Charles Lyons)

 
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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,
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 203
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic