[Technology Sharing]20171229_spring MVC _ Spring MVC file Upload

Source: Internet
Author: User

Here I want to say the point is: this method File.transferto (newFile), do not have to go to hand-written file upload, directly with this method can

Here is the JSP

<formname= "Form2"Action= "/springmvc006/fileupload2"Method= "POST"enctype= "Multipart/form-data"><H1>Upload files using the File.transfer method provided by multipart</H1><inputtype= "File"name= "File"><inputtype= "Submit"value= "Upload"/></form> 

Note This annotation @RequestParam ("file") .

@RequestMapping ("FileUpload2")     PublicString FileUpload2 (@RequestParam ("file")Commonsmultipartfile file)throwsIOException {LongStarttime=System.currenttimemillis (); System.out.println ("FileName:" +file.getoriginalfilename ()); String Path= "e:/" +NewDate (). GetTime () +File.getoriginalfilename (); File NewFile=NewFile (path); //write the file directly by Commonsmultipartfile (note this time)File.transferto (NewFile); LongEndtime=System.currenttimemillis (); System.out.println ("Method two run Time:" +string.valueof (endtime-starttime) + "MS"); return"/success"; }

[Technology Sharing]20171229_spring MVC _ Spring MVC file Upload

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.