1.1.
Configure the virtual directory
Configure the picture virtual directory on Tomcat and add it under Tomcat under conf/server.xml :
<context docbase= "D:\develop\upload\temp" path= "/pic" reloadable= "false"/>
access http://localhost:8080/pic to access the pictures under D: \develop\upload\temp.
You can also configure through Eclipse , such as:
------------------------------------------------------------
1.2.
Configuring the Upload parser
Configuring the File Upload parser in springmvc.xml
<!--file upload, id must be set to Multipartresolver--
<bean id="Multipartresolver"
class="Org.springframework.web.multipart.commons.CommonsMultipartResolver">
<!--set File upload Size--
<property name="maxuploadsize" value="5000000" />
</bean>
---------------------------------------------------------
Set up a form to upload files, such as:
---------------------------------------------------------------
@RequestMapping (value = "/updateitem.action")
Public Modelandview UpdateItem (items items) {This name is the same as the Name property of the JSP page
Public String UpdateItem (Queryvo vo,multipartfile picturefile) throws exception{
Save picture to
String name = Uuid.randomuuid (). toString (). ReplaceAll ("-", "");
Jpg
String ext = filenameutils.getextension (Picturefile.getoriginalfilename ());
Picturefile.transferto (New File ("d:\\upload\\" + name + "." + ext));
Vo.getitems (). Setpic (name + "." + ext);
Modify
Itemservice.updateitemsbyid (Vo.getitems ());
Modelandview Mav = new Modelandview ();
Mav.setviewname ("Success");
Return "redirect:/itemedit.action?id=" + vo.getitems (). GetId ();
return "Forward:/item/itemlist.action";
}
--------------------------------------------------------------------------
<tr>
<td> Product Images </td>
<td>
<c:if test= "${item.pic!=null}" >
<br/>
</c:if>
<input type= "File" name= "PictureFile"/>
</td>
</tr>
Springmvc File Upload