What does it mean when its said getWriter() returns the printwriter object???...
Printwriter out =new Printwriter()
this also should create a printwriter object
then why this Printwriter out =response.getwriter()
And... response object can call get Writer method since it is inherited from servletResponse( interface).. tat means getwriter is abstract method..
so where is the implementation for getWriter() ...?
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32712
4
posted
0
Welcome to the Ranch
Careful about spellings: getwriter() and getWriter() are different things.
If you use a get method, you obtain a reference to whatever that object already has as a field. So response.getWriter() will give you whichever Writer response is already using.
If you write new Writer(), however, you get a completely different Writer.
Rajeev Hegde
Greenhorn
Joined: Aug 04, 2010
Posts: 2
posted
0
Thanks for replying
I understood.
But when is the first time response gets write object and who gives it? container?
I've a doubt regarding this. If we use two reference to refer this PrintWriter, what will happen? I used it, but the output is different, when we write using these two reference. Why is that?
|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
Without knowing what you actually did, it's impossible to answer that question. If you have two references to the same object there will be no difference.
David Newton wrote:Without knowing what you actually did, it's impossible to answer that question. If you have two references to the same object there will be no difference.
In a JSP page, I've used two references to refer the same PrintWriter object, with the use of getWriter() method. And, I used this two reference to write the output. But they aligned in different way.