For a long time did not write the file upload code, the following code support asynchronous upload, notes.
1. Page Setup
<div><input type= "File" class= "Easyui-linkbutton" id= "Excelfile" name= "Excelfile" size= "maxlength=" 20 "/ ><input type= "button" class= "Easyui-linkbutton" onclick= "UploadFile ()" style= "width:80px" value= "Upload"/> </div>
2. JS Code
function UploadFile () { var url = "Upload.htm?method=upload ')", var formData = new FormData (); Formdata.append (' Excelfile ', $ (' #excelFile ') [0].files[0]); Jquery.ajax ({ url:url, type: ' POST ', cache:false, data: FormData, processdata:false, Contenttype:false}). Done (function (res) {Console.log (res);}). Fail (function (res) {Console.log ("failed=" +res);}); </
3. Action Code
@RequestMapping (value= "/upload.htm", params = "method=upload") public String Upload (@RequestParam ("Excelfile") Multipartfile file, Modelmap model,httpservletresponse response) { String fileName = File.getoriginalfilename (); C12/>inputstream is = File.getinputstream ();}
Ajax Springmvc uploading files asynchronously