First upload file is based on two JS library implementation of JQuery (I used jquery-2.1.4.js) ajaxfileupload.js (there are multiple versions, there may be version bugs)
HTML section
<!--must have the name and id attribute-->
<input id= "imgfile" type= "file" Name= "fil"/>
JS part
$ (document). Ready (function () {/* Note: 1>inpu
T file must have the name attribute 2>ajaxfileupload datatype must be uppercase or Google browser will not complain
*///When file selects $ ("#imgFile"). On (' Change ', function () {$.ajaxfileupload ({
URL: ' filecontroller/fileupload ',//For file Upload server-side request address secureuri:false,//Whether a security protocol is required, generally set to False
Fileelementid: ' Imgfile ',//File upload domain ID dataType: ' JSON ',//return value type
Success:function (data, status) {//Server Success Response processing function alert (data);
}, Error:function (data, status, E) {//server response failure processing function
E Exception Information alert (e);
}
});
}); });
Background section
/**
* Note: multipartfile must be labeled
* @RequestParam ("fil")
* fil is the name of the front-end file] * * Uploadutil.uploadimg () for the background upload method,
* Internal will return JSON data, returned to the picture address *
* *
@RequestMapping ("FileUpload") Public
void FileUpload (HttpServletRequest request,
httpservletresponse response,
@RequestParam (" Fil ") multipartfile file {
try {
uploadutil.uploadimg (request, response, file);
} catch (IOException e) {
e.printstacktrace ();
}
}