How to read message attachments without scripting in JSP?

I want to know how to read attachment messages without scripting in JSP? After getting the Message object as an attribute using the request object from the servlet, how can I confirm whether the Message content is a Multipart instance or not, without using scripts like:

 if(message.getContent() instanceOf Multipart)

      

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

+2


source to share


2 answers


Add those getters to the class 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();
}

      



This way you can use it in JSTL / EL:

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

      

+2


source


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



  • a boolean

    indicates if there are attachments
  • attachment list
+1


source







All Articles