Java Reference
In-Depth Information
Parsing multipart/form-data
Correctly parsing data that arrives in the
multipart/form-data
MIME type is surprisingly difficult. Instead of reinventing the
wheel, Stripes delegates this unpleasant piece of work to third-
party libraries that have already solved the problem. The Stripes
distribution includes two such libraries: Apache Commons File-
Upload
∗
and COS.
†
Stripes automatically uses the implementation that it finds in
the class path. To use Commons File Upload, copy
commons-
fileupload.jar
and
commons-io.jar
to the
WEB-INF/lib
directory. For
COS, use
cos.jar
. If Stripes finds both libraries, Commons FileU-
pload is chosen.
So, how do you decide between Commons FileUpload and
COS? Basically, the advantage of COS is that it's only one JAR
file instead of two. However, the license for Commons FileU-
pload is more permissive; it caches small files in memory instead
of writing them to disk, improving performance; and, unlike
COS, Commons FileUpload is still being maintained.
Of course, if you know of another implementation, you can
plug it in. The strategy for handling multipart form data is
represented in Stripes by the
MultipartWrapper
interface. This is
an extension, so placing your implementation in an extension
package would have Stripes use it automatically.
∗.
†.
<c:if test="${not empty actionBean.message.attachments}">
<div>
Attachments:
</div>
<div>
<c:forEach var="attachment"
items="${actionBean.message.attachments}">
<s:link event="downloadAttachment"
beanclass="stripesbook.action.MessageDetailsActionBean">
<s:param name="attachmentId" value="${attachment.id}"/>
${attachment.fileName}
</s:link>
(${attachment.size} bytes)
<br/>
</c:forEach>
</div>
</c:if>
Search WWH ::
Custom Search