Bootstrap Fileupload 文件上传

1.在jsp中引入css与js文件,

  <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>----字体

2.在jsp中初始化文件上传控件:

$(document).ready(function(){
/* 输入框联想 */
new CommunitySelect(‘searchCommunityName‘,‘${ctx}‘);
$(‘#table‘).bootstrapTable({
method:‘post‘
});

$("#edit").on("hidden.bs.modal", function(){
$(this).removeData("bs.modal");
});
//文件上传
$(‘#file-zh‘).fileinput({
language: ‘zh‘,
maxFilesNum: 1,
maxFileSize: 5000,
uploadUrl:uploadUrl: ‘${ctx}/mindex/importCityIndex.do‘, //请求的路径

showUpload: true,

showRemove: true,
uploadAsync: true,
showPreview : true,
showCancel : false,
allowedFileExtensions: [‘xlsx‘, ‘xls‘]    //限定文件的类型
});
});

$("#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.在jsp中主体部分添加弹出窗体<div class="modal fade" id="uploadModal" tabindex="-1" role="basic" aria-hidden="true">

    <form enctype="multipart/form-data" id="uploadForm" method="post">        <div class="modal-dialog">            <div class="modal-content">                <div class="modal-header">                    <button type="button" class="close" data-dismiss="modal"                            aria-hidden="true"></button>                    <h4 class="modal-title">导入</h4>

                    <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、在controller中添加handler
@RequestMapping("importCityIndex")@ResponseBodypublic AjaxJson importCommunity(@RequestParam("xlsFile") MultipartFile file) throws IOException{  //file   得到要上传文件的输入流对象  
InputStream inputStream = file.getInputStream();
}
时间: 2024-08-03 15:48:30

Bootstrap Fileupload 文件上传的相关文章

fileupload文件上传

在使用java开发文件上传时,网络上有很多不一样的工具.但是每次如果都需要开发一次,对于使用者来说,这个过程是浪费时间的.所以我们有必要选取其中一个适合自己的文件上传组件,然后对其进一步分装,形成自己的开发工具类.下面我针对自己的工程,对fileupload进行了封装. fileupload是apache的一个组件,要想使用fileupload,需要用到下面两个jar:commons-fileupload-1.3.1.jar,commons-io-1.1.jar(版本不一样,可能相关jar包不一

改变FileUpload文件上传控件的显示方式,确认后上传

一.Aspx页面: <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="FileUploadDemo.aspx.cs" Inherits="WebApplication1.FileUploadDemo" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN&qu

简单的FileUpload文件上传

引入jar包:commons-fileupload-1.3.1.jar,commons-io-1.3.2.jar 前台HTML: <form action="./upload" method="post" enctype="multipart/form-data"> <table> <tr> <td><label>用户名:</label></td> <td&

对FileUpload文件上传控件的一些使用方法说明

//可以上传图片,txt文档.doc,wps,还有音频文件,视屏文件等,功能强大啊! //前台代码片,设置上传图片的界面 <div> <asp:Label ID ="lbText" runat ="server" Font-Bold ="true" Font-Size ="20px" Text ="请选择您要上传的照片"> </asp:Label> <br />

SSH框架 FileUpLoad文件上传

文件上传是很常用的一个功能,今天说一下struts2的文件上传,使用的是fileupload组件. 首先要有两个jar包,如下图所示: 如果没有这两个jar包的话上传肯定不会成功的,控制台会报错的. 然后再页面上要有一个上传文件的标签,如下图所示: 不要在意后面的onchange事件,这个是做的一个图片上传,为了能够点击图片直接弹出文件选择框而写的一个函数,顺便提一下吧,具体函数和做法如下图所示: 下面是函数: 这个...下面言归正传,继续说文件上传,页面上的上传文件的标签最重要的就是type=

bootstrap fileinput 文件上传工具

这是我上传的第二个plugin 首先第一点就是因为这个好看 符合bootstrap的界面风格 第二是可以拖拽(虽然我不常用这个功能 但是这样界面看起来就丰满了很多) 最后不得不吐槽这个的回发事件 我百度了很久才找到 CSDN上面也问了 不知道是自己百度的方式不正确还是别的什么原因..好吧 我蠢 地址  http://plugins.krajee.com/file-input https://github.com/kartik-v/bootstrap-fileinput 效果图 这里以我一个项目的

改变FileUpload文件上传控件的显示方式,选择文件后自动上传

一.Aspx页面: <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="FileUploadDemo.aspx.cs" Inherits="WebApplication1.FileUploadDemo" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN&qu

commons.fileupload 文件上传

编辑jsp页面获取文件 1 <html> 2 <head> 3 <base href="<%=basePath%>"> 4 5 <title>My JSP 'upload.jsp' starting page</title> 6 7 <meta http-equiv="pragma" content="no-cache"> 8 <meta http-equi

FileUpload 文件上传

实现文件的上传功能现在有两种方式: FileUpload jar包 javax-servlet-api 的 HttpServletRequest接口中的getPart()方法 首先使用第一种: 1.创建项目,引入commons-fileupload jar 和javax.servlet-api 2.创建jsp页面: 3.程序处理: @WebServlet("/upload") public class Upload extends HttpServlet { @Override pro