I'm developing some custom JSP tags. In my SimpleTag.doTag()
I grab the JspContext
and call getOut()
to get the JspWriter
. When writing to JspWriter
, what's the different between write(String)
and print(String)
? Should I be calling one instead of the other?
views:
427answers:
2
+3
A:
The print() method can buffer, the write() method is inherited from the Writer class and cannot - so you may get better performance from the JspWriter's print() method.
In addition, the print() method is overloaded to take many different types of objects as an argument, whereas the write method deals in Strings and chars only.
See the JspWriter javadocs for more details.
Brabster
2009-01-29 17:54:17
So it sounds like print is the preferred method.
Steve Kuo
2009-01-29 17:59:04
Depends on what you want to do, but I'd say yes in most cases - it's specifically purposed to be used with JSP, as opposed to the generic Writer abstract class which you'd need to use to leverage polymorphism.
Brabster
2009-01-29 18:01:15
+1
A:
from the javadoc:
The 'write' function was inherited from java.io.writer .
The 'print' function: prints "null" if the argument was null. Otherwise, the string's characters are written to the JspWriter's buffer or, if no buffer is used, directly to the underlying writer.
Pierre
2009-01-29 17:56:15