多文件上传
来源:互联网 发布:网络在线平交流平台 编辑:程序博客网 时间:2024/05/18 05:06
<%@ page contentType="text/html;charset=UTF-8" language="java" %><html><head> <title>Title</title></head><body><h1>文件上传</h1><form action="/firstt" method="post" enctype="multipart/form-data"> 文件 1 <input type="file" name="upload"/> 文件 2 <input type="file" name="upload"/> 文件 3 <input type="file" name="upload"/> <input type="submit"/></form></body></html>
Controller:
@Controllerpublic class FirstController { @RequestMapping("/firstt") public String doFirst(MultipartFile[] upload, HttpSession session) { for (MultipartFile item : upload) { //判断用户是否选择文件 if (item.getSize()>0){ //获取到用户上传文件的名称 String childpath=item.getOriginalFilename(); //判断选择的文件格式 if (childpath.endsWith(".jpg")){ //将相对路径转换成绝对路径 String parentPath=session.getServletContext().getRealPath("/uploa"); //将file写入指定路径 File filepath=new File(parentPath,childpath); try { item.transferTo(filepath); } catch (IOException e) { e.printStackTrace(); return "/index.jsp"; } }else{ return "/index.jsp"; } }else{ return "/index.jsp"; } } return "/index.jsp"; }}
配置:
<!--扫描器--><context:component-scan base-package="wenjiansahngchuan"></context:component-scan><mvc:annotation-driven/><bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> <property name="defaultEncoding" value="utf-8"></property> <property name="maxUploadSize" value="5000000"></property></bean>
阅读全文
0 0
- 文件上传(多文件)
- asp.net文件上传,多文件上传。
- 单文件上传、多文件上传
- struts2文件上传与多文件上传
- 单文件上传和多文件上传
- PHP文件上传功能 -- 多文件上传
- struts2文件上传(多文件上传)
- SpringMVC文件上传 多文件上传实例
- Struts2之文件上传,多文件上传
- SpringMVC文件上传 多文件上传实例
- 文件上传及多文件上传
- Spring boot 文件上传(多文件上传)
- Struts文件上传--2.多文件上传
- spring boot文件上传【多文件上传】
- FastDFS上传文件二 : 多文件上传
- 多文件上传
- 单/多文件上传
- 多个文件上传
- 微信小程序开发过程中遇到的问题
- CAN总线与CANOPEN协议
- POJ 1321
- 图文详解 IntelliJ IDEA 15 创建普通 Java Web 项目
- 113. Path Sum II
- 多文件上传
- JS中的表格排序和关于DOM映射机制
- echarts中画布的清空
- [编程题] 最大的奇约数
- [Leetcode] 576. Out of Boundary Paths
- bfs 大逃亡
- 「LibreOJ β Round #4」求和 莫比乌斯函数
- 调用摄像头功能的方法详解
- 35、异步编程和多线程编程的区别