<!-- Other code omitted -->
</div>
In Listing 17-54, the changes are highlighted in bold. In the <form:form> tag, we need to enable the
multipart file upload support by specifying the attribute enctype. Next, the file upload field is added to
the form.
We also need to modify the show view to display the photo for a contact. Listing 17-55 shows the
changes required to the view (show.jspx).
Listing 17-55. Show Contact View for Display File
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Other code omitted -->
<spring:message code="label_contact_photo" var="labelContactPhoto"/>
<spring:url value="/contacts/photo" var="contactPhotoUrl"/>
<!-- Other code omitted -->
<tr>
<td>${labelContactDescription}</td>
<td>${contact.description}</td>
</tr>
<tr>
<td>${labelContactPhoto}</td>
<td><img src="${contactPhotoUrl}/${contact.id}"></img></td>
</tr>
<!-- Other code omitted -->
</div>
In Listing 17-55, the changes are highlighted in bold. A new row is added to the table for displaying
the photo by pointing to the URL for photo download, as specified in Table 17-5.
Modify Controller for File Upload Support
The final step is to modify the controller. We need to make two changes. The first change is to the
create() method to accept the upload file as a request parameter. The second change is to implement a
new method for photo download based on the supplied contact ID. Listing 17-56 shows the revised
ContactController class.
Listing 17-56. Revised Controller Class with File Upload and Download Support
package com.apress.prospring3.ch17.web.controller;
import javax.servlet.http.Part;
// Other import statements omitted
@RequestMapping("/contacts")
@Controller
public class ContactController {
@RequestMapping(method = RequestMethod.POST)
Search WWH :
Custom Search
Previous Page
Spring Framework 3 Topic Index
Next Page
Spring Framework 3 Bookmarks
Home