JQuery File Upload combined with SPRINGMVC

Source: Internet
Author: User
Tags jquery file upload

The jquery file upload contains a bunch of files that first need to figure out what the core part is, and according to the official example, one of the simplest jquery file upload upload components must include the following files: The jquery core library, It is recommended to use the jquery 1.8 version Js/vendor/jquery.ui.widget.js:jquery UI widget Js/jquery.iframe-transport.js: Extending the IFRAME data transfer js/ Jquery.fileupload.js:jQuery File upload Core class js/cors/jquery.xdr-transport.js should load this file to solve cross-domain problems under IE

You only need to load one upload button at this time

<input id= "FileUpload" type= "file" Name= "Attch" data-url= "server/php/" multiple>

And one line of code

$ (' #fileupload '). FileUpload ();  

A basic upload component is completed. This simplest upload component can submit selected files as forms to the Data-url Convention URL, while providing enough settings and base events to scale.

For the background, you need to increase SPRINGMVC support for uploads, adding configuration to the Springcontext.xml

<bean id= "Multipartresolver" class= "Org.springframework.web.multipart.commons.CommonsMultipartResolver"/>

If you are using MAVEN management, you need to add the following references

<dependency>
	<groupId>commons-fileupload</groupId>
	<artifactId> commons-fileupload</artifactid>
	<version>1.3</version>
</dependency>	

The following documents are obtained from the controller

@RequestMapping (value = "/upload/{adid}", method = requestmethod.post) public
	@ResponseBody String upload (@ Requestparam (value = "File", Required = False) Multipartfile file, @PathVariable String adid) {

			file F=new file (ad_pict Ures_location+adid+ "/" +file.getoriginalfilename ());
			try {
				fileutils.copyinputstreamtofile (File.getinputstream (), f);
			} catch (IOException e) {
				E.printstacktrace ();
			}
			 
			return "Fileuploaddone";  

	}


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.