In my servlet I gave both out.print
and out.write
. but both prints in the browser.
What is the exact difference between these two and when to use out.print
and out.write
?
In my servlet I gave both out.print
and out.write
. but both prints in the browser.
What is the exact difference between these two and when to use out.print
and out.write
?
out.write(-) vs out.print(-)
One more difference is out.write(-) method just write data or object to browser like a file. You can not write any statement like out.write(10*20); but we do this with out.print(10*20);
The out variable in your case is most likely refers to a PrintWriter
Just compare the description of write...
... with the description of println ...
... and print ...
All in all I'd say that the print methods work on a higher level of abstraction and is the one I prefer to work with when writing servlets.
I simply know it as like this:
out.println()
is method ofjavax.servlet.jsp.JspWriter
out.write()
is method ofjava.io.Writer