spring mvc file upload
文件上传
1.需要导入两个jar包
2.在SpringMVC配置文件中加入
|
1
2
3
4
|
<!-- upload settings --><bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> <property name="maxUploadSize" value="102400000"></property></bean> |
3.方法代码
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
@RequestMapping(value="/upload",method=RequestMethod.POST)public String upload(HttpServletRequest req) throws Exception{ MultipartHttpServletRequest mreq = (MultipartHttpServletRequest)req; MultipartFile file = mreq.getFile("file"); String fileName = file.getOriginalFilename(); SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss"); FileOutputStream fos = new FileOutputStream(req.getSession().getServletContext().getRealPath("/")+ "upload/"+sdf.format(new Date())+fileName.substring(fileName.lastIndexOf('.'))); fos.write(file.getBytes()); fos.flush(); fos.close(); return "hello";} |
4.前台form表单
|
1
2
3
4
|
<form action="mvc/upload" method="post" enctype="multipart/form-data"> <input type="file" name="file"><br> <input type="submit" value="submit"></form> |
spring mvc file upload的更多相关文章
- Spring MVC 文件上传 & 文件下载
索引: 开源Spring解决方案--lm.solution 参看代码 GitHub: pom.xml WebConfig.java index.jsp upload.jsp FileUploadCon ...
- Spring MVC 学习第一篇
很好的MVC 参考blog:http://jinnianshilongnian.iteye.com/blog/1752171 MVC: 概念:是一种设计模式,并没有引入新的技术,只是把我们开发的结构组 ...
- File upload in ASP.NET Core web API
参考1:File upload in ASP.NET Core web API https://www.janaks.com.np/file-upload-asp-net-core-web-api/ ...
- Spring MVC-表单(Form)标签-文件上传(File Upload)示例(转载实践)
以下内容翻译自:https://www.tutorialspoint.com/springmvc/springmvc_upload.htm 说明:示例基于Spring MVC 4.1.6. 以下示例显 ...
- Spring MVC文件上传出现错误:Required MultipartFile parameter 'file' is not present
1.配置文件上传的解析器 首先需要在spring mvc的配置文件中(注意是spring mvc的配置文件而不是spring的配置文件:applicationContext.xml)配置: sprin ...
- Spring mvc 中使用ftl引用共通文件出错 FreeMarker template error: Error reading included file "/WEB-INF/ftl/common/errormessage.ftl"
初次接触spring mvc,想做一个小的练习项目,结果在ftl文件中引用其它的共通ftl文件时出错.
- 我是如何进行Spring MVC文档翻译项目的环境搭建、项目管理及自动化构建工作的
感兴趣的同学可以关注这个翻译项目 . 我的博客原文 和 我的Github 前段时间翻译的Spring MVC官方文档完成了第一稿,相关的文章和仓库可以点击以下链接.这篇文章,主要是总结一下这个翻译项目 ...
- spring mvc文件上传(单个文件上传|多个文件上传)
单个文件上传spring mvc 实现文件上传需要引入两个必须的jar包 1.所需jar包: commons-fileupload-1.3.1.jar ...
- java spring mvc restful 上传文件
spring mvc 配置文件 <bean class="com.baiyyy.yfz.core.RestfulHandlerMethodMapping" /> ...
随机推荐
- 使用Visual Studio 2013进行单元测试
使用Visual Studio 2013进行单元测试 1.打开VS2013 --> 新建一个项目.这里我们默认创建一个控制台项目.取名为UnitTestDemo 2.在解决方案里面新增一个单元测 ...
- 单片机pc指针
单片机的PC是指程序计数器(Program Counter).程序计数器PC用于存放下一条将要执行的指令地址,是一个16位专用寄存器,不能通过MOV指令来操作,对用户来说是不可见的.当执行一条指令时, ...
- OneZero第四周第五次站立会议(2016.4.15)
1. 时间: 15:00--15:15 共计15分钟. 2. 成员: X 夏一鸣 * 组长 (博客:http://www.cnblogs.com/xiaym896/), G 郭又铭 (博客:http ...
- SpringBoot 5.SpringBoot小知识讲解
1.修改 server 端口: 在 application.properties 中添加 server.port=9090,我们的端口号就会变成9090了. 2.自定义配置Web: 2.1 创建 Cu ...
- 基于Vue-cli 快速搭建项目
Vue-cli可以快速帮助我们创建一个项目,这是官方给我们提供的脚手架.下面我说一下vue-cli的使用方法. 一.准备工作 在使用vue-cli时,首先需要安装nodejs,npm,其次需全局安装v ...
- linux服务器mysql数据库新建数据库并配置数据库用户
第一步:进入数据库 mysql -uroot -p 提示输入密码,输入你的root用户密码(默认不显示) 如下图: 第二步:创建一个数据库 create database 数据库名称 ;(注意分号结尾 ...
- PyQt4 安装
安装PyQt4很简单,从官网下载相应的安装包即可. 需要注意的是:应该根据你电脑上已经装好的python版本选择相应的PyQt4安装包. PyQt4的安装目录一定要选python的安装目录,比如我的P ...
- RabbitMQ 客户端开发向导
准备工作:composer 引入 php-amqplib 说明:本文说明基于 Java(主要说明原理),实现使用 php RabbitMQ Java 客户端使用 com.rabbitmq.client ...
- IAR ------ 基本使用
1.编译结果: 6 887 bytes of readonly code memory 621 bytes of readonly data memory 331 bytes of readwrite ...
- Git error: hint: Updates were rejected because the remote contains work that you do hint: not have locally
hint: Updates were rejected because the remote contains work that you dohint: not have locally. This ...