CommonsMultipartFile

Spring提供的读取文件的类,使用方便,依赖spring-web-3.1.2.RELEASE.jar

包路径:

java.lang.Object

  org.springframework.web.multipart.commons.CommonsMultipartFile

方法汇总:
 
byte[] getBytes()  Return the contents of the file as an array of bytes.
String getContentType()  Return the content type of the file.
FileItem getFileItem() Return the underlying org.apache.commons.fileupload.FileItem instance
InputStream getInputStream() Return an InputStream to read the contents of the file from.
String getName() Return the name of the parameter in the multipart form.
String getOriginalFilename()   Return the original filename in the client's filesystem.
long getSize() Return the size of the file in bytes.
String getStorageDescription()  Return a description for the storage location of the multipart content.
protected  boolean isAvailable() Determine whether the multipart content is still available.
boolean isEmpty()   Return whether the uploaded file is empty, that is, either no file has been chosen in the multipart form or the chosen file has no content.
voic transferTo(File dest)    Transfer the received file to the given destination file.

使用方法:

1.spring配置文件配置文件上传解析器
    <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">         <property name="defaultEncoding" value="utf-8"></property>         <property name="maxUploadSize" value="90000000" />         <property name="uploadTempDir" value="uploadFiles"></property>     </bean>
2.html写法注意两点
    a.input类型为file:<input type="file" name="sealPfxFile"  id="sealPfxFile" size="24" />
    b.form中增加参数enctype="multipart/form-data":
       <form id="addSeal" name="addSeal" action="${root}/seal/o_add.do" enctype="multipart/form-data" method="post">
 
3.Service的写法(注意与html中定义的名称相同即可通过get方法取得需要的内容)
public String doAction(@RequestParam("sealPfxFile") CommonsMultipartFile sealPfxFile, Seal seal, ModelMap modelMap, HttpServletRequest request) throws Exception {
      //上传文件名
      String fileName = sealPfxFile.getFileItem().getName();
  //上传文件流
      InputStream is = sealPfxFile.getInputStream();
}

CommonsMultipartFile---用Spring实现文件上传的更多相关文章

  1. Spring MVC 笔记 —— Spring MVC 文件上传

    文件上传 配置MultipartResolver <bean id="multipartResolver" class="org.springframework.w ...

  2. spring实现文件上传(图片解析)

    合抱之木,生于毫末,千里之行,始于足下,要想了解spring的文件上传功能,首先要知道spring是通过流的方式将文件进行解析,然后上传.那么是不是所有需要用的文件上传的地方都要写一遍文件解析器呢? ...

  3. Spring Boot 文件上传原理

    首先我们要知道什么是Spring Boot,这里简单说一下,Spring Boot可以看作是一个框架中的框架--->集成了各种框架,像security.jpa.data.cloud等等,它无须关 ...

  4. Spring MVC文件上传教程 commons-io/commons-uploadfile

    Spring MVC文件上传教程 commons-io/commons-uploadfile 用到的依赖jar包: commons-fileupload 1.3.1 commons-io 2.4 基于 ...

  5. spring boot文件上传、下载

    主题:Spring boot 文件上传(多文件上传)[从零开始学Spring Boot]http://www.iteye.com/topic/1143595 Spring MVC实现文件下载http: ...

  6. springboot成神之——spring的文件上传

    本文介绍spring的文件上传 目录结构 配置application DemoApplication WebConfig TestController 前端上传 本文介绍spring的文件上传 目录结 ...

  7. 【Java Web开发学习】Spring MVC文件上传

    [Java Web开发学习]Spring MVC文件上传 转载:https://www.cnblogs.com/yangchongxing/p/9290489.html 文件上传有两种实现方式,都比较 ...

  8. Spring mvc文件上传实现

    Spring mvc文件上传实现 jsp页面客户端表单编写 三个要素: 1.表单项type="file" 2.表单的提交方式:post 3.表单的enctype属性是多部分表单形式 ...

  9. 用Spring实现文件上传(CommonsMultipartFile)!

    2012-02-16 18:10:26|  分类: 计算机--JAVA EE-|字号 订阅 spring中的文件上传实际比较容易1.页面中<html>   <body>   & ...

  10. SpringMVC , Spring , MyBatis 文件上传

    学习一下文件上传下载,为图片上传做准备,感觉有一个世纪没玩过上传下载了,边敲代码边记录,请各路大神指教: 参考:http://blog.csdn.net/wjycgl/article/details/ ...

随机推荐

  1. promise待看文档备份

    http://swift.gg/2017/03/27/promises-in-swift/ http://www.cnblogs.com/feng9exe/p/9043715.html https:/ ...

  2. java操作Excel的poi的简介

    一.POI概述 Apache POI是Apache软件基金会的开放源码函式库,POI提供API给Java程序对Microsoft Office格式档案读和写的功能. 结构: HSSF - 提供读写Mi ...

  3. day06-08面向对象的三大特性

    一.继承 1.1什么是继承?继承是一种创建新类的方式,在python中,新建的类可以继承一个或多个父类,父类又可称为基类或超类,新建的类称为派生类或子类python中类的继承分为:单继承和多继承 cl ...

  4. C语言提高 (5) 第五天 结构体,结构体对齐 文件

    1昨日回顾 2作业讲解 3 结构体的基本定义 //1 struct teacher { int id; char name[64]; }; struct teacher t5 = { 5, " ...

  5. [luogu2047 NOI2007] 社交网络 (floyed最短路)

    传送门 输入输出样例 输入样例#1: 4 4 1 2 1 2 3 1 3 4 1 4 1 1 输出样例#1: 1.000 1.000 1.000 1.000 题解 在进行floyed的过程中,顺便更新 ...

  6. nmcli 静态方式添加IP地址

    [root@ansible02:/root] > ip a 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state U ...

  7. Django入门--模型系统(二):常用查询及表关系的实现

    1.常用查询 模型类上的管理器: ** 模型类.objects ** (1)常用一般查询 rs = Student.objects.all() # 查询所有记录,返回Queryset print(rs ...

  8. 导出MNIST的数据集

    在TensorFlow的官方入门课程中,多次用到mnist数据集. mnist数据集是一个数字手写体图片库,但它的存储格式并非常见的图片格式,所有的图片都集中保存在四个扩展名为idx3-ubyte的二 ...

  9. RobotFrameWork+APPIUM实现对安卓APK的自动化测试----第一篇【安装】

    文章来源http://blog.csdn.net/deadgrape/article/details/50563119 前言:关于RobotFrameWork+APPIUM实现对安卓APK的自动化测试 ...

  10. mobile touch 备用

    var _scrollIndex=1; function scrollPage(){ var _contentEle = $('.view-container'),_viewEle = _conten ...