. html
<th data-options= "field: ' Op ', align: ' center ', Width:220,formatter:rmtmanager.supportopformmater ()" > Operation </ Th>
<div id= "Uploadcertificate" >
<div class= "Easyui-layout" data-options= "Fit:true" >
<div data-options= "region: ' Center '" style= "padding:10px;" >
<div style= "margin-bottom:20px" >
<form id= "Excelform" method= "post" enctype= "Multipart/form-data" >
<div> Please select the certificate to upload:</div>
<input name= "Certificate"Class=" Easyui-filebox "data-options=" required: ' true ', ButtonText: ' Select File ' "style=" width:100% ">
<input type= "hidden" id= "AccountId" name= "accountId" value= ""/>
</form>
</div>
</div>
<div data-options= "region: ' South ', Border:false" style= "text-align:right;padding:5px 0 0;" >
<a id= "Import" href= "#" class= "Easyui-linkbutton" data-options= "iconcls: ' Icon-ok '" > Uploads </a>
<a id= "Cancel" href= "#" class= "Easyui-linkbutton" data-options= "iconcls: ' Icon-cancel '" > Cancel </a>
</div>
</div>
</div>
. js
(function ($) {
var pagetype= $ (' #glPageType '). Val ();
var ctx= $ (' #ctx '). Val ();
var editindex = undefined;
var busmng = Rmtcmhelper.createbusmnginst ({
busmngoptions:{
toupload:function (flag) {
$ (' #accountId '). val (flag);
$ (' #uploadCertificate '). Window ({
width:300,
height:150,
Title: ' Certificate import ',
Minimizable:false,
Maximizable:false,
Collapsible:fals E,
Modal:true
});
$ (' #uploadCertificate '). Window (' open ');
},
supportopformmater:function () {
return function (value,row,index) {
Re Turn ' <a href= "javascript:void (0);" class= "Todo" onclick= "Rmtmanager.totoken (' +row.id+ ')" > View token</a> '
+ ' <a href= "javascript:void (0);" class= "Todo" onclick= "rmtmanager.addconfig (' +row.id+ ')" > Configuration </A&G t; '
+ ' <a href= "javascript:void (0);" class= "Todo" onclick= "Rmtmanager.toview (' +row.id+ ')" > View </a>& amp;nbsp; '
+ ' <a href= ' javascript:void (0); "class=" Todo "onclick=" rmtmanager.toupload (' +row.id+ ') > on Certificate </a> ';
}
}
});
$ (' #import '). Bind (' click ', Function () {
$ (' #excelform '). Form (' Submit ', {
url:ctx+ "/wxb Ase/account/upload.html ",
Onsubmit:function () {
if ($ (' #excelform '). Form (' Validate '))
Rmthelper.showmask ();
},
Success:function (data) {
var data = eval (' (' + data + ') ');
if (data.success) {
Rmthelper.hidemask ();
$ (' #uploadCertificate '). Window (' close ');
Rmthelper.showmsg (data.content);
Rmthelper.getcurcurdist (). Reloadgrid ();
}else{
Rmthelper.hidemask ();
Rmthelper.showmsg (data.content);
}
}
});
});
$ (' #cancel '). Bind (' click ', Function () {
$ (' #uploadCertificate '). Window (' close ');
});
Controller
/**
* Upload Certificate
* @param request
* @return
*/
@RequestMapping (value= "Upload", method = Requestmethod.post)
@ResponseBody
Public Resultjsoninfo uploadcertificate (@RequestParam ("Certificate") MultipartfileCertificate, HttpServletRequest request) throws Exception {
String accountId = Request.getparameter ("AccountId");
String filename= "";
try {
String Picpath = "d://" + accountId + "/";
Determine if a certificate existed before
File Certificatefile = new file (picpath+accountid+ ". cer");
if (certificatefile.exists ()) {
The existing certificate is deleted
Certificatefile.delete ();
}
Create a catalog file based on a real path
File Picsavefile = new file (Picpath);
Determine if a path exists
if (!picsavefile.exists ()) {
Create a path if it does not exist
Picsavefile.mkdirs ();
}
if (!certificate.isempty ()) {
try {
byte[] buffer =new byte[1024*1024];
int bytesum = 0;
int byteread = 0;
Filename=accountid+ ". cer";
FileOutputStream fs=new FileOutputStream (Picpath + fileName);
Bytesum+=byteread;
Fs.write (Buffer,0,byteread);
System.out.println ("File Stream" +certificate.getoriginalfilename ());
Dump file */
/*certificate.transferto (New File (Picpath)); */
} catch (Exception e) {
E.printstacktrace ();
}
return new Resultjsoninfo (true, "upload succeeded" + ",");
}
}catch (Exception e) {
E.printstacktrace ();
return new Resultjsoninfo (false, "upload failed" + ",");
}
/*logger.info ("Import successful number of strokes:" +count+ ", Time:" + (End-start) + "milliseconds"); */
return new Resultjsoninfo (true, "upload succeeded" + ",");
}
The purple ones have to be named the same.
Ajax+multipartfile uploading files to a local