JspWriter 写入与打印
我正在开发一些自定义 JSP 标签。 在我的 SimpleTag.doTag()
中,我获取 JspContext
并调用 getOut()
来获取 JspWriter
。 写入 JspWriter
时,write(String)
和 print(String)
有什么区别? 我应该打电话给其中一个而不是另一个吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
print() 方法可以缓冲,而 write() 方法是从 Writer 类继承的,不能缓冲 - 因此您可以从 JspWriter 的 print() 方法获得更好的性能。
此外,print() 方法被重载以将许多不同类型的对象作为参数,而 write 方法仅处理字符串和字符。
有关详细信息,请参阅 JspWriter javadocs 。
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.
来自 javadoc:
'write' 函数继承自 java.io.writer 。
'print' 函数:如果参数为 null,则打印“null”。 否则,字符串的字符将写入 JspWriter 的缓冲区,或者如果未使用缓冲区,则直接写入底层编写器。
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.