1. The introduction of CSS and JS files in JSP,
<link href= "${ctx}/plugins/fileup/css/fileinput.css" media= "All" rel= "stylesheet" type= "text/css"/>----CSS
<script type= "Text/javascript" src= "${ctx}/plugins/fileup/js/fileinput.js"/>----js
<script src= "${ctx}/plugins/fileup/js/fileinput_locale_th.js" type= "Text/javascript" ></script>----
<script src= "${ctx}/plugins/fileup/js/fileinput_locale_zh.js" type= "text/javascript" ></script>----fonts
2. Initialize the file upload control in the JSP:
$ (document). Ready (function () {
/* Input Box Lenovo */
New Communityselect (' Searchcommunityname ', ' ${ctx} ');
$ (' #table '). Bootstraptable ({
Method: ' Post '
});
$ ("#edit"). On ("Hidden.bs.modal", function () {
$ (this). Removedata ("Bs.modal");
});
File Upload
$ (' #file-zh '). Fileinput ({
Language: ' en ',
Maxfilesnum:1,
maxfilesize:5000,
Uploadurl:uploadurl: ' ${ctx}/mindex/importcityindex.do ', //path requested
Showupload:true,
Showremove:true,
Uploadasync:true,
Showpreview:true,
Showcancel:false,
Allowedfileextensions: [' xlsx ', ' xls ']//Limit the type of file
});
});
$ ("#file-zh"). On ("fileuploaded", function (event, data, Previewid, index) {
var result = Data.response;
if (result.success) {
$ ("#uploadModal"). Modal ("Hide");
$ (' #table '). Bootstraptable ("refresh");
Bootbox.alert (RESULT.MSG);
} else {
Bootbox.alert (RESULT.MSG);
}
});
3. Add a pop-up form <div class= "Modal Fade" id= "Uploadmodal" tabindex= "1" role= "basic" aria-hidden= "true" in the main part of the JSP >
<form enctype= "Multipart/form-data" id= "Uploadform" method= "post";
<div CLA Ss= "Modal-dialog",
<div class= "modal-content";
<div class= "Modal-header" >
<button type= "button" class= "Close" data-dismiss= "modal"
Aria-hi Dden= "true" ></BUTTON>
<div class= "Modal-body",
<div class= "Form-group";
<input id= "File-zh" name= "Xlsfile" type= "file" MULTIPLE>
</div>
</div>
</div>
</div>
</div>
</form>
</div>
4, add handler
in controller
@RequestMapping ("Importcityindex")
@ResponseBody
Public Ajaxjson importcommunity (@RequestParam ("Xlsfile") Multipartfile file) throws ioexception{
file gets the input stream object to upload
InputStream InputStream = File.getinputstream ();
}
Bootstrap Fileupload File Upload