• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem with response.getWriter()

 
reubin haz
Ranch Hand
Posts: 287
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I saw a question with code inside a jsp:

<%
PrintWriter out = response.getWriter();
out.write("P"); %>

with explanation: "It is a bad idea to use the response's PrintWriter directly. You should instead use the JspWriter associated with the out implicit variable. The effects of buffering can jumble the output if out and the response's PrintWriter are mixed."

But I'm not quite understand why it is a bad idea. Someone please explain, thanks.
 
Anbu Rajendran
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JspWriter has a different buffering behavior from PrintWriter.
By default, the implicit JspWriter object available to JSP
is buffered.

If you try to use both writers in the same page and they
have different buffering behaviors (one is buffered and
the other is not), you will have problems.

Try reading this page
http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/servlet/jsp/JspWriter.html
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic