There are two ways of handling file uploads in spring MVC:
(1) Use common fileup element.
(2) Support for file uploads using Servlet 3.0 and later.
One, client-side programming
In order to upload a file, to set the HTML table's enctype to Multipart/form-data, the table also has a type file INPUT element, it will be displayed as a button, the click will open a Select File dialog box.
As follows:
<form action= "Action" enctype= "Multipart/form-data" method= "post> Select files <input type=" file "Name=" Filedname "/multiple> <input type=" Submit "value=" Upload "/></form>
Before HTML5, if you want to upload more than one file, write multiple input, with HTML5, only add multiple attribute in input.
Second, Multipartfile interface
Files that have been uploaded to spring MVC are wrapped in a Mutlipartfile object, and the only thing we need to do is write a domain class with a property of type Multipartfile.
The next step is how to get the files that have been uploaded in the controller.
Third, upload files with common FileUpload
There are two jar files to use here:
Commons-fileupload.jar
Common-io.jar
Also define the Multipartresolver bean in the Springmvc-servlet.xml file
<bean id= "Multipartresolver" class= "Org.springframework.web.multipart.commons.CommonsMultipartResolver" <property name= "mxcuploadsize" value= "2000000"/></bean>
11th chapter-Uploading Files