jquery file Bulk Upload control Uploadify3.2 (Java SPRINGMVC)

Source: Internet
Author: User

People are more lazy and helpful.


First put on the uploadify link: http://www.uploadify.com/---inside can see the PHP Demo sample, property Description, as well as the control. Divided into Flash version (free) and HTML5 version (charge).

Can see the effect demonstration on the website.


Also found on the Internet a copy of the Uploadify3.2 Chinese API document. Can be downloaded in the resources I upload.


Here is an example of a file upload demo based on SPRINGMVC, which may seem more intuitive than a document ...


1. Download the plugin into your project


2. Introduce the following JS and CSS in the JSP page

<script type= "Text/javascript" src= "${ctxstatic}/uploadify/jquery.uploadify.min.js" ></script>< Link type= "text/css" rel= "stylesheet" href= "${ctxstatic}/uploadify/uploadify.css" >

Create Presentation div and action button in 3.jsp page

</pre><pre name= "code" class= "HTML" ><form><div id= "queue" ></div><!-upload queue display area-- <input id= "File_upload" name= "file_upload" type= "file" multiple= "true" ><!-bulk upload button--></form>

4. Edit the JS code

$ (document). Ready (function () {$ ("#file_upload"). Uploadify ({' swf ': ' ${ctxstatic}/uploadify/geo_fileupload.swf ',// The control Flash file location//Background processing request (that is, the action request path), followed by a jsessionid to indicate the use of the current session (the default is to open a new session.) Result in a 302 error in the request that the session checksum is present) ' uploader ': ' ${ctx}/testfu;jsessionid=${pagecontext.session.id} ', ' queue ID ': ' Queue ',//div.id corresponding to the following HTML ' width ': ' + ',//button width ' height ': ' + ',//button height ' filetypedesc ': ' Specify type file ', ' Filetypeexts ': ' *.jpg;*.png ',//control the extension of the uploaded file, enable this item at the same time to declare Filedesc ' fileobjname ': ' Mytestfile ',//file object name, Used in the background to obtain the file object, as described in the following Java code ' ButtonText ': ' Bulk upload ',//Upload button display content. There is also a property to set the button's background image ' Filesizelimit ': ' 100KB ', ' Multi ': true, ' overrideevents ': [' ondialogclose ', ' onuploadsuccess ', ' Onuploaderror ', ' Onselecterror '],//overrides the default method ' Onfallback ': function () {//Detect Flash failed call alert ("You do not have Flash control installed. Can't upload pictures! Please install the Flash control and try again.

");},//The following method is the corresponding overrideevents overloaded method, the detailed implementation is found on the internet a friend's code,//I drew these methods into a self-defined JS 。 I will put it on the last side of ' OnSelect ': uploadify_onselect, ' onselecterror ': uploadify_onselecterror, ' Onuploaderror ' : Uploadify_onuploaderror, ' onuploadsuccess ': uploadify_onuploadsuccess});

Methods of the 5.controller class

<pre name= "code" class= "HTML" > @ResponseBody @requestmapping (value = "Testfu")
        Here's <span style= "font-family:arial, Helvetica, Sans-serif;" >creativefile and </span><span in JSP space above style= "font-family:arial, Helvetica, Sans-serif;" >creativefile corresponding </span><span style= "font-family:arial, Helvetica, Sans-serif;" ></span>public String testupload (multipartfile creativefile, httpservletresponse response) { System.out.println (Creativefile.getname ()); System.out.println (Creativefile.getoriginalfilename ()); System.out.println (Creativefile.getsize ()); return "test";//returns to the foreground message}

6. The appendix is from the list of overloaded methods on the web, and I made some changes to make it more useful (thanks to the network of unknown experts)

var uploadify_onselecterror = function (file, ErrorCode, errormsg) {var msgtext = "Upload failed \ n"; switch (errorCode) {case Swfuplo Ad. Queue_error. queue_limit_exceeded://this.queueData.errorMsg = "Upload at most" +//This.settings.queueSizeLimit + "files"; Msgtext + = " The number of uploaded files has exceeded the system limit of "+ $ (' #file_upload '). Uploadify (' Settings ', ' queuesizelimit ') +" Files! "; Break;case Swfupload.queue_error. File_exceeds_size_limit:msgtext + = "file [" + File.name + "] size exceeds system limit of" + $ (' #file_upload '). Uploadify (' Settings ', ' fileSize Limit ') + "size. "; Break;case Swfupload.queue_error. Zero_byte_file:msgtext + = "File size is 0"; Break;case swfupload.queue_error.  Invalid_filetype:msgtext + = "file format is not valid, only" + This.settings.filetypeexts;break;default:msgtext + = "Error code:" + ErrorCode + "\ n" + errormsg;} alert (msgtext);}; var uploadify_onuploaderror = function (file, ErrorCode, ErrorMsg, errorstring) {//manual cancel does not eject prompt if (ErrorCode = = Swfupload.up Load_error. file_cancelled | | ErrorCode = = Swfupload.upload_error. upload_stopped) {return;} var msgtext = "Upload failed \ n"; switch(ErrorCode) {Case Swfupload.upload_error. Http_error:msgtext + = "HTTP error \ n" + errormsg;break;case Swfupload.upload_error. Missing_upload_url:msgtext + = "Upload file lost, please upload again"; Break;case Swfupload.upload_error. Io_error:msgtext + = "IO error"; Break;case swfupload.upload_error. Security_error:msgtext + = "Security error \ n" + errormsg;break;case Swfupload.upload_error. Upload_limit_exceeded:msgtext + = "Upload at maximum" + This.settings.uploadLimit + "one"; Break;case swfupload.upload_error. Upload_failed:msgtext + = Errormsg;break;case swfupload.upload_error. Specified_file_id_not_found:msgtext + = "Cannot find the specified file. Please operate again "; Break;case Swfupload.upload_error. File_validation_failed:msgtext + = "parameter error"; Break;default:msgtext + = "File:" + file.name + "\ n error code:" + ErrorCode + "\ n" + errorm sg + "\ n" + errorstring;} alert (msgtext);} var uploadify_onselect = function () {};var uploadify_onuploadsuccess = function (file, data, response) {alert (" Save the relevant information returned in the background of each file upload, and show it in the Onqueuecomplete method "); var uploadify_onqueuecomplete = function () {alert ("all finished-and show cue Message");} 

To this uploadify file batch upload is OK. If you have any questions, we can discuss them together. This control is very easy to take time to read and can be understood. The purpose of writing this article is also to let everyone get started faster. Save valuable time




jquery file Bulk Upload control Uploadify3.2 (Java SPRINGMVC)

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.