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. 【seo】title / robots / description / canonical

    1.title title,就是浏览器上显示的那些内容,不仅用户能看到,也能被搜索引擎检索到(搜索引擎在抓取网页时,最先读取的就是网页标题,所以title是否正确设置极其重要. 1)title一般不超 ...

  2. 前端自动化构建yeoman

    前端自动化可分为: yo(脚手架工具).grunt(构建工具).bower(包管理器). OMAN的特性 http://yeoman.io/learning/   闪电般的初始化:项目开始阶段,可以基 ...

  3. 解读:20大5G关键技术

    解读:20大5G关键技术 5G网络技术主要分为三类:核心网.回传和前传网络.无线接入网. 核心网 核心网关键技术主要包括:网络功能虚拟化(NFV).软件定义网络(SDN).网络切片和多接入边缘计算(M ...

  4. Bootstrap 4 - Glyphicons migration?

     https://stackoverflow.com/questions/32612690/bootstrap-4-glyphicons-migration Migrating from Glyphi ...

  5. JSCH实现文件上传下载至sftp服务器

    文件服务器采用FreeSSHd,文件服务器配置就不细说了. 直接上代码,该代码可以直接使用. import com.jcraft.jsch.*; import java.io.InputStream; ...

  6. SQL SEVER 递归查询

    with ts as ( --首先要查询出最原始父级的信息 union all --全连接 select a.fitemclassid,a.fitemid, a.fnumber,a.Fparentid ...

  7. vue中使用base64进行加解密

    vue进行Base64加解密 背景 项目中需要对特殊字符进行处理,避免json和数据库的特殊字符(""等)冲突,刚好学了信息安全,干脆整个加解密,wkk.. 使用步骤 打开dos, ...

  8. [luogu2585 ZJOI2006] 三色二叉树 (树形dp)

    传送门 Description Input 输入文件名:TRO.IN 输入文件仅有一行,不超过500000个字符,表示一个二叉树序列. Output 输出文件名:TRO.OUT 输出文件也只有一行,包 ...

  9. 作为深度学习最强框架的TensorFlow如何进行时序预测!(转)

    作为深度学习最强框架的TensorFlow如何进行时序预测! BigQuant 2 个月前 摘要: 2017年深度学习框架关注度排名tensorflow以绝对的优势占领榜首,本文通过一个小例子介绍了T ...

  10. (7)JPA - Hibernate【从零开始学Spring Boot】

    在说具体如何在spring boot 使用Hibernate前,先抛装引玉些知识点?什么是JPA呢? JPA全称Java Persistence API.JPA通过JDK 5.0注解或XML描述对象- ...