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

Dbt on ServletOutputStream

 
Vineela Devi
Ranch Hand
Posts: 191
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
Its given in HFS book tht PrintWriter Wraps ServletOutPutStream.so we can write

If thts the case why we cant we write the same for OutputStream as

instead of


Thanks in advance

Vineela
 
Debashish Chakrabarty
Ranch Hand
Posts: 231
Firefox Browser Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

PrintWriter out = response.getOutPutStream();
instead of
ServletOutPutStream out = response.getOutputStream();


Question is why would you want to do that?

The rationale lies in the purpose for a Writer and an OutputStream. A Writer (which is what a PrintWriter basically is) is primarily meant for text output (i.e. normal text or HTML or XML etc). The ServletOutputStream is primarily meant for binary data, it is not basically for text based writing.

So when you are downloading a PDF file generated on the fly you would perhaps use the ServletOutputStream and when just displaying a simple page with a form and Javascript validation, a PrintWriter would suffice.

Does that make sense?
[ April 21, 2005: Message edited by: Debashish Chakrabarty ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic