11th chapter-Uploading Files

Source: Internet
Author: User

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

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.