如何在 JSP 中不使用 scriptlet 读取附件消息?

发布于 2024-08-28 10:46:46 字数 315 浏览 3 评论 0原文

我想知道如何在 JSP 中不使用 scriplet 来读取附件消息?通过使用 servlet 中的 request 对象获取 Message 对象作为属性后,如何在不使用 scriplet 的情况下确认 Message 内容是否是 Multipart 的实例:

 if(message.getContent() instanceOf Multipart)

How can I read the content of any file by using EL in JSP?因为我在 inputStream 子类中看不到任何 getRead 方法。

I want to know how can I read attachment messages without using scriplets in JSP? After getting Message object as an attribute by using request object from servlets, how can I confirm whether Message content is an instance of Multipart or not without using scriplets like:

 if(message.getContent() instanceOf Multipart)

How can I read the content of any file by using EL in JSP? As I can't see any getRead method in inputStream subclass.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

能怎样 2024-09-04 10:46:46

自己将这些 getter 添加到 Message 类中:

public boolean isMultipart() {
    return (getContent() instanceof Multipart);
}

public String getContentAsString() {
    StringBuilder builder = new StringBuilder();
    // Append using BufferedReader/InputStreamReader. If necessary, do it lazily.
    return builder.toString();
}

这样您就可以在 JSTL/EL 中使用它:

<c:if test="${message.multipart}">
    <c:out value="${message.contentAsString}" />
</c:if>

Add those getters to the Message class yourself:

public boolean isMultipart() {
    return (getContent() instanceof Multipart);
}

public String getContentAsString() {
    StringBuilder builder = new StringBuilder();
    // Append using BufferedReader/InputStreamReader. If necessary, do it lazily.
    return builder.toString();
}

This way you can use it in JSTL/EL:

<c:if test="${message.multipart}">
    <c:out value="${message.contentAsString}" />
</c:if>
睫毛上残留的泪 2024-09-04 10:46:46

也在 servlet 中执行此逻辑,并且仅“发送”将用于呈现给 jsp 的数据。在本例中发送:

  • 是否有附件
  • 一个 boolean 指示附件列表中

Perform this logic in the servlet as well, and "send" only data that will be used for presentation to the jsp. In this case send:

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