input file multiple 配合springmvc实现多文件上传
来源:互联网 发布:上海地铁免费查询软件 编辑:程序博客网 时间:2024/05/22 17:15
1、前端页面的样子
<input id="file" name="file" type="file" multiple="multiple" />
2、前端的js代码
var formData = new FormData(); var files = $("#file")[0].files;for(var i = 0 ; i < files.length ; i ++){formData.append('file',files[i]);}3、ajax的代码
$.ajax({ url: '${cpath}/biz/xxxx/addFile', type: 'POST', cache: false, data: formData, processData: false, contentType: false}).done(function(res) {debugger;});
4、后端的代码
@RequestMapping(value = "addFile", method = RequestMethod.POST, produces = "application/json; charset=UTF-8")@ResponseBodypublic String addFile(HttpServletRequest request,HttpServletResponse response) {String rRoles = request.getParameter("rRoles");List<MultipartFile> fileList = new ArrayList<>();//创建一个通用的多部分解析器 CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver(request.getSession().getServletContext());//判断 request 是否有文件上传,即多部分请求 if(multipartResolver.isMultipart(request)){ //转换成多部分request MultipartHttpServletRequest multiRequest = (MultipartHttpServletRequest)request; //取得request中的所有文件名 fileList = multiRequest.getFiles("file"); if (fileList == null || fileList.size() <= 0) {throw new Exception("上传文件失败");} System.out.println(""); }return null;}5、xml配置文件配置
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> <!-- set the max upload size100MB --> <property name="maxUploadSize"> <value>104857600</value> </property> <property name="maxInMemorySize"> <value>4096</value> </property> </bean>6、jar包,除了springmvc常规的jar,还需要commons-fileupload-1.2.2.jar
*注意:关于formdata
The append()
method of the FormData
interface appends a new value onto an existing key inside a FormData
object, or adds the key if it does not already exist.
The difference between FormData.set
and append()
is that if the specified key already exists, FormData.set
will overwrite all existing values with the new one, whereas append()
will append the new value onto the end of the existing set of values.
阅读全文
0 0
- input file multiple 配合springmvc实现多文件上传
- html5中的input(type="file")的multiple属性,实现多文件上传,并用js控制文件大小,数量
- input文件选择框 springmvc实现多文件上传
- input file实现多选和限制文件上传类型
- input File实现同时上传多个文件
- 使用SpringMVC配合jQuery文件上传插件ssi-uploader实现多图片可预览上传
- input file 上传文件
- input file文件上传
- 用Ajax配合Restull实现SpringMVC的文件上传
- PHP 多input file文件上传
- 多文件上传(input标签file)
- input标签file 多文件上传
- 在ASP.NET中实现多文件上传(三)---jQuery Multiple File Upload Plugin
- input为file上传文件
- input为file上传文件
- SpringMVC File Upload 多文件上传
- multiple file upload 多文件上传精典
- input type=file 只读,并能实现文件上传
- 通过可视化数据分析提升测试质量
- 软考分页存储求物理地址公式
- 路由侧边栏
- bzoj 3563: DZY Loves Chinese
- 30 个最好的数据可视化工具推荐
- input file multiple 配合springmvc实现多文件上传
- 一图看懂:2017年中国自媒体从业人员生存状况
- Impala修改/删除/清空表操作
- 五步教你设计成功而有价值的数据可视化
- Java泛型详解
- 如何将数据可视化技术应用于广告投放?
- JavaScript字符串操作
- IDEA快捷键Mac版本
- 0.从零开始学JAVA