| Author |
why we go for response.getWriter()
|
Arun Maalik
Ranch Hand
Joined: Oct 25, 2005
Posts: 216
|
|
Dear sir why we go for response.getWriter() ,PrintWriter is a class we can make the object via PrintWriter obj=new PrintWriter();Why we did like that in every servlet program. Thanks and Regards Arun kumar maalik
|
 |
Ben Souther
Sheriff
Joined: Dec 11, 2004
Posts: 13410
|
|
Look again at the API for the PrintWriter class. http://java.sun.com/j2se/1.5.0/docs/api/java/io/PrintWriter.html There is no empty constructor. In order to create one, you need something some kind of outputstream or file. The container insures that you have a valid outputstream that will go back to the client.
|
Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
|
 |
Scott Selikoff
Saloon Keeper
Joined: Oct 23, 2005
Posts: 3652
|
|
If you're asking why its done that way everytime (I agree that it is repetitive), its because java is not a pure web language. Most of the use of java in servlet/jsps are extensions of the language in order to make it more accessible to web programmers. Its why PHP is often a lot faster than writing in JSP/Servlets, but with the added work comes more power and more control. For example, you can have servlets that perform work and never use the print writer.
|
My Blog: Down Home Country Coding with Scott Selikoff
|
 |
Arun Maalik
Ranch Hand
Joined: Oct 25, 2005
Posts: 216
|
|
|
Thanks sir
|
 |
William Brogden
Author and all-around good cowpoke
Rancher
Joined: Mar 22, 2000
Posts: 12266
|
|
For servlets to work, it must be possible to configure the response output stream for binary output (images, etc) or character output (HTML) under the programmers control. Therefore we have getWriter() and getOutputStream() - the programmer must choose the appropriate one. Bill
|
Java Resources at www.wbrogden.com
|
 |
 |
|
|
subject: why we go for response.getWriter()
|
|
|