This article mainly introduces the sample code for asynchronous upload using jquery. upload. js. If you need it, you can refer to the following resources to download: upload
1: jsp code:
Import jquery. upload. js and jquery-1.7.2.js
Add the code to call js: Upload
Write at the bottom:
2: js Code:
/* File Upload */function doUpload () {// upload method $. upload ({// upload url: window. basePath + '/reply/imageUpload', // file domain name fileName: 'uploadfile', // other form data params :{}, // After the upload is complete, return json, textdataType: 'json', // callback before upload. return true indicates that onSend: function () {return true ;}, onSubmit: function (){}, // callback onComplate: function (data) {if (data. msg) {} else {alert ("An error occurred while uploading the image! ");}}});}
3: Background code:
/*** Upload image to the local server * @ param request * @ param response * @ return */@ RequestMapping (value = "imageUpload") @ ResponseBodypublic Object imageUpload (HttpServletRequest request, httpServletResponse response) {Map
Map = new HashMap
(); UploadUtil uploadUtil = new UploadUtil (); try {String url = uploadUtil. excelUpload (request, response); // File Upload} catch (IOException e) {e. printStackTrace ();} return map ;}