Springmvc file upload, using the Multipartfile

Source: Internet
Author: User
Tags file upload

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 (

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.