Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top