The required racks for uploading files using Commons-fileupload are: Commons-fileupload and Common-io two Rack pack support, which can be smashed on the Apache website.
To configure uploads in profile Spring-mvc.xml:
<id= "Multipartresolver" class= " Org.springframework.web.multipart.commons.CommonsMultipartResolver ">//File Upload max is how much
<name= "Maxuploadsize" value= "10485760000"/ >//Upload file encoding method
<name= "defaultencoding" value= "Utf-8"/>// Maximum cache size in memory
<name= "Maxinmemorysize" value= "40960"/> </bean>
In the corresponding JSP page there are two main points to note, asked form form the method= "post" and enctype= "Multipart/form-data", the others are usually written.
The corresponding code in the controller that is submitted to spring MVC is as follows:
@RequestMapping (value= "/upload.do", method=requestmethod.post) publicthrows ioexception{ for(multipartfile file:files) { if(! File.isempty ()) { new File ("E:/file" +file.separator+file.getoriginalfilename ())} } return "Uploadok"; }
Adding @requestparam code in the main is to deal with multiple files when uploading, if it is a single file upload can not be written.
File uploads in spring MVC