views:

86

answers:

2

Hi,

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.

+1  A: 

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
Bozho
+2  A: 

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>
BalusC