springMVC上传文件简单案例
2024-08-24 13:36:12
html
<form name="Form2" action="/SpringMVC006/fileUpload2" method="post" enctype="multipart/form-data">
<h1>采用multipart提供的file.transfer方法上传文件</h1>
<input type="file" name="file">
<input type="submit" value="upload"/>
</form>
配置springmvc.xml:
1
2
3
4
5
6
|
<!-- 多部分文件上传 --> <bean id= "multipartResolver" class = "org.springframework.web.multipart.commons.CommonsMultipartResolver" > <property name= "maxUploadSize" value= "104857600" /> <property name= "maxInMemorySize" value= "4096" /> <property name= "defaultEncoding" value= "UTF-8" ></property> </bean> |
使用方法:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
/* * 采用file.Transto 来保存上传的文件 */ @RequestMapping ( "fileUpload2" ) public String fileUpload2( @RequestParam ( "file" ) CommonsMultipartFile file) throws IOException { long startTime=System.currentTimeMillis();
String path= "E:/" + new Date().getTime()+file.getOriginalFilename(); File newFile= new File(path); //通过CommonsMultipartFile的方法直接写文件(注意这个时候) file.transferTo(newFile);
return "/success" ; } |
最新文章
- iOS程序破解——获取.ipa程序包
- React Native 开发之 (01) 配置开发环境
- Centos中文乱码的解决方法
- ubuntu安装rpm包
- EventBus代替Intent将复杂对象传递给下一个即将启动的Activity
- Java 语言细节
- Java数据库连接池
- oop、configparser、xml模块
- hdu - 3952 Fruit Ninja(简单几何)
- 在自己的对象里实现IEnumerator和IEnumerable
- 使用git对unity3d项目进行版本控制
- Lua脚本之语法基础快速入门
- 设置nginx禁止通过IP访问服务器的方法
- WinForm小小应用
- Java NIO系列教程(六) 多路复用器Selector
- codevs 2622 数字序列
- 异常来自 HRESULT:0x80070057 (E_INVALIDARG)(转)
- NN:神经网络实现识别手写的1~9的10个数字—Jason niu
- Alpha版本发布时间安排
- LeetCode题解之Missing Number
热门文章
- Jack Straws(poj 1127) 两直线是否相交模板
- noip第27课作业
- POJ3320 Jessica&#39;s Reading Problem 2017-05-25 19:55 38人阅读 评论(0) 收藏
- scrapy分布式
- AngularJS config run 及区别和例子
- firefox浏览器testclient测试接口
- vsm安装
- 有人在用fastReport作报表时处理过字体自动缩小的问题吗,怎么做
- https://www.cnblogs.com/hnxxcxg/p/6085149.html
- 怎么找到与你Eclipse匹配的spring tool suite插件