Bootstrap Fileupload File Upload

Source: Internet
Author: User
Tags button type

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.