JspWriter 写入与打印

发布于 2024-07-13 02:34:26 字数 258 浏览 4 评论 0原文

我正在开发一些自定义 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

羅雙樹 2024-07-20 02:34:26

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.

南薇 2024-07-20 02:34:26

来自 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文