<!-- Other code omitted -->
</web-app>
The change is highlighted in bold. In Servlet 3.0, the servlet that supports file upload should be
provided with a <multipart-config> tag to configure the support. The <max-file-size> tag controls the
maximum file size allowed for upload, which is 5MB.
Second, we need to configure a bean that implements the MultipartResolver interface in the
DispatcherServlet's WebApplicationContext. Listing 17-53 shows the bean definition that you need to
add to the file (servlet-context.xml).
Listing 17-53. Configure the MultipartResolver Support in Spring MVC
<beans:bean
class="org.springframework.web.multipart.support.StandardServletMultipartResolver"
id="multipartResolver"/>
Note the implementation class StandardServletMultipartResolver, which is new in Spring 3.1 for
supportinging native file upload in the Servlet 3.0 container.
Modify Views for File Upload Support
We need to modify two views for file upload support. The first one is the edit view (edit.jspx) to support
photo upload for a contact, and the second one is the show view (show.jspx) for displaying the photo.
Listing 17-54 shows the changes required for the edit view.
Listing 17-54. Edit Contact View for File Upload Support
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Other code omitted -->
<form:form modelAttribute="contact" id="contactUpdateForm" method="post"
enctype="multipart/form-data">
<!-- Other code omitted -->
<form:label path="description">
${labelContactDescription}
</form:label>
<form:textarea cols="60" rows="8" path="description" id="contactDescription"/>
<div>
<form:errors path="description" cssClass="error" />
</div>
<p/>
<label for="file">
${labelContactPhoto}
</label>
<input name="file" type="file"/>
<p/>
Search WWH :
Custom Search
Previous Page
Spring Framework 3 Topic Index
Next Page
Spring Framework 3 Bookmarks
Home