• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSPWriter vs. PrintWriter

 
Ken Duncan
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JSPs get translated to servlets. According to the Heads First book, on p.age 338, "out" is a javax.servlet.jsp.JspWriter. So I have two questions. First, is there a way to know, besides memorizing details in the spec, to know when something is a "servlet" class and when something is a "JSP" class? In the preceding pages, the book emphasizes that application, request, etc., are servlet-related classes because every JSP is turned into a servlet. Having out be a JSPWriter and not a PrintWriter seems to be an exception to this "rule," so I'm concerned to be able to tell the difference. Second, what does a JSPWrtier get translated into in the generated servelet class? Thanks.

Ken
 
amer abushamma
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JSPs should use the JspWriter denoted by the “out” implicit object for sending output back to the client. A
JspWriter is a buffered version of the PrintWriter. Refer JspWriter API for details. JspWriter also differs from a PrintWriter by throwing java.io.IOException, which a PrintWriter does not. The advantage of throwing an exception is that if your HTTP connection is broken for some reason, your JSP won’t sit there trying to send characters to a broken connection.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic