One, the configuration file:
Springmvc used the Multipartfile to upload the file, so we'll first configure the Multipartresolver: To process the form file
[HTML] view Plain copy <!--configuration multipartresolver for file uploads using spring Commosmultipartresolver--and <bean S:bean id= "Multipartresolver" class= "Org.springframework.web.multipart.commons.CommonsMultipartResolver" P:defau ltencoding= "UTF-8" p:maxuploadsize= "5400000" p:uploadtempdir= "fileupload/temp" > </ Beans:bean>
The attributes are detailed in the following:
Defaultencoding= "UTF-8" is the requested encoding format, the default is Iso-8859-1
Maxuploadsize= "5400000" is the size of the uploaded file, in bytes
Uploadtempdir= "Fileupload/temp" is the temporary path for uploading files
Second, create a simple upload form:
[HTML] view plain copy <body> Note To add enctype= "Multipart/form-data" to the form label means that the form is to process the file, which is the most basic thing, many people will forget but when the upload error, then go to find the program error, but forget this
Third, write the Upload control class
1. Create a control class: Fileuploadcontroller and a page that returns results list.jsp
2. Write the action to submit the form:
[Java] View plain copy//Get the Spring default configuration request by using spring autowired annotations @Autowired private HttpServletRequest request; /*** * uploading files Use @requestparam annotations to specify that file on the form is multipartfile * * @param file * @return */ @RequestMapping ("FileUpload") public string fileupload (@RequestParam (