Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JspWriter write versus print

Tags:

java

jsp

jsp-tags

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?

like image 364
Steve Kuo Avatar asked Jan 29 '09 17:01

Steve Kuo


2 Answers

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.

like image 155
brabster Avatar answered Nov 20 '22 11:11

brabster


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.

like image 3
Pierre Avatar answered Nov 20 '22 09:11

Pierre