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. (转)基于MVC4+EasyUI的Web开发框架形成之旅--权限控制

    http://www.cnblogs.com/wuhuacong/p/3361351.html 我在上一篇随笔<基于MVC4+EasyUI的Web开发框架形成之旅--框架总体界面介绍>中大 ...

  2. ZBrush的双十一来了,然鹅...

    不管是“光棍节”还是“剁手节” 似乎和我都没有什么关系 事实证明,我错了 今早竟然有不识趣的人发红包祝我单身快乐 纳尼,这是唱的哪一出? 我能直接怼回去,说不领么? 但好像又不是我的风格 哎,一个红包 ...

  3. 一系列令人敬畏的.NET核心库,工具,框架和软件

    内容 一般 框架,库和工具 API 应用框架 应用模板 身份验证和授权 Blockchain 博特 构建自动化 捆绑和缩小 高速缓存 CMS 代码分析和指标 压缩 编译器,管道工和语言 加密 数据库 ...

  4. 记一次IOS对 JS的支持问题

    最终在这位博主那块找到问题https://blog.csdn.net/github_36487770/article/details/82465741 在利用Vue开发一个功能时遇到时间拼接格式化问题 ...

  5. Python基础:使用list & tuple

    list Python内置的一种数据类型是列表:list.list是一种有序的集合,可以随时添加和删除其中的元素. tuple 小结 list和tuple是Python内置的有序集合,一个可变,一个不 ...

  6. git入坑随笔

    一直以来,都喜欢用git做版本管理,主要涉及平台是coding, github以及公司自己搭建的gitlab. 因为一直以来都是自己一个人维护前端的项目,所以基本上很少有冲突的情况.(手动微笑 :) ...

  7. 原生node实现简易留言板

    原生node实现简易留言板 学习node,实现一个简单的留言板小demo 1. 使用模块 http模块 创建服务 fs模块 操作读取文件 url模块 便于path操作并读取表单提交数据 art-tem ...

  8. 记一次生产主机中挖矿病毒"kintegrityds"处理过程!

    [记一次生产挖矿病毒处理过程]: 可能性:webaap用户密码泄露.Jenkins/redis弱口令等. 1.监控到生产主机一直load告警 2.进服务器 top查看进程,发现挖矿病毒进程,此进程持续 ...

  9. 小松之LINUX 驱动学习笔记(二)

    这两天一直在看字符驱动那块,后来从网上找啦几个例子,自己编译啦下,安装啥的都挺正常,就是用测试程序测试的时候总出问题,现在找到一个能测试的代码,自己先看看和原来的那个代码有啥不同,后面会继续更新,说下 ...

  10. ContextLoaderListener的说明

    ContextLoaderListener是配置在web.xml里的,具体如下: <!-- ContextLoaderListener是个监听器,用来监听容器启动事件,监听到容器启动事件后 其c ...