Originally done is from the form of file upload, and later because of the need to use Ajax asynchronous, so contact with the jquery uploadify upload
Put code on it for reference
JS files that need to be introduced
<href= "... /res/uploadify/uploadify.css " rel=" stylesheet " type=" Text/css"/> <src= ".. /res/uploadify/jquery.uploadify.min.js " type=" Text/javascript"></ Script >
Here is the HTML code
<type= " file" id= "File " name= " file" />
Here's the jquery code
The blue part below is useless .
$ ("#file"). Uploadify ({height:14, swf: '/res/uploadify/uploadify.swf ', Uploader: '. /member/getallbyexcel ', width:100, filetypeexts: ' *.xls ', errormsg: ' Unsupported file format ', ButtonText: "Excel upload", Multi:false, Onuploadsuccess:function (File,data, state) {var jsondata =$.parsejson (da Ta.replace (/\\/g, "\\\\")); if (data.msg) {alert (unescape (data.msg)); Return } $.appendmainpic (Jsondata.images[0].url,jsondata.images[0].id); var Orgvalue = $ ("#Card_Pic_mainPic"). Val () + ""; orgvalue+= "," +jsondata.images[0].id; $ ("#Card_Pic_mainPic"). Val (Orgvalue); }, Onqueuecomplete:function (a,b,c) {}});
Here is the background code
@RequestMapping (value= "Getallbyexcel", method =requestmethod.post) PublicObject getallbyexcel (httpservletrequest request,httpservletresponse response, Modelmap model) {Map<string, object> resmap=NewHashmap<string, object>(); Multiparthttpservletrequest mulltipartrequest=(multiparthttpservletrequest) request; Map<string, multipartfile> filemap =Mulltipartrequest.getfilemap (); for(Map.entry<string, multipartfile>Entity:fileMap.entrySet ()) {multipartfile Files=Entity.getvalue (); //multipartfile MF = entity.getvalue ();String path=request.getsession (). Getservletcontext (). Getrealpath ("/web-inf/res/upload"); String FileName=Files.getoriginalfilename (); Try{InputStream InputStream=Files.getinputstream (); byte[] B =New byte[1048576]; intLength =Inputstream.read (b); Path+= "\\" +FileName; //file stream writes to server sideFileOutputStream OutputStream =NewFileOutputStream (path); Outputstream.write (b,0, length); Inputstream.close (); Outputstream.close (); } Catch(Exception e) {e.printstacktrace (); } } //multipartfile files=mulltipartrequest.getfile (null); //get the Upload server pathResmap.put ("MSG", "Entry Success"); returnResmap; }
Record-jquery uploadify File upload instance