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"
    }

最新文章

  1. iOS程序破解——获取.ipa程序包
  2. React Native 开发之 (01) 配置开发环境
  3. Centos中文乱码的解决方法
  4. ubuntu安装rpm包
  5. EventBus代替Intent将复杂对象传递给下一个即将启动的Activity
  6. Java 语言细节
  7. Java数据库连接池
  8. oop、configparser、xml模块
  9. hdu - 3952 Fruit Ninja(简单几何)
  10. 在自己的对象里实现IEnumerator和IEnumerable
  11. 使用git对unity3d项目进行版本控制
  12. Lua脚本之语法基础快速入门
  13. 设置nginx禁止通过IP访问服务器的方法
  14. WinForm小小应用
  15. Java NIO系列教程(六) 多路复用器Selector
  16. codevs 2622 数字序列
  17. 异常来自 HRESULT:0x80070057 (E_INVALIDARG)(转)
  18. NN:神经网络实现识别手写的1~9的10个数字—Jason niu
  19. Alpha版本发布时间安排
  20. LeetCode题解之Missing Number

热门文章

  1. Jack Straws(poj 1127) 两直线是否相交模板
  2. noip第27课作业
  3. POJ3320 Jessica&#39;s Reading Problem 2017-05-25 19:55 38人阅读 评论(0) 收藏
  4. scrapy分布式
  5. AngularJS config run 及区别和例子
  6. firefox浏览器testclient测试接口
  7. vsm安装
  8. 有人在用fastReport作报表时处理过字体自动缩小的问题吗,怎么做
  9. https://www.cnblogs.com/hnxxcxg/p/6085149.html
  10. 怎么找到与你Eclipse匹配的spring tool suite插件