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" /> ...
随机推荐
- DirectoryEntry_Properties属性的遍历(win2003)
DirectoryEntry root = new DirectoryEntry(@"IIS://localhost/W3SVC"); string PInfo = "& ...
- Objective-C语言--self和super关键字解析
看代码: @implementation Son : Father - (id)init{ self = [super init]; if (self){ } return self; } self是 ...
- 什么是GPS的冷启动、温启动和热启动?
对于GPS多种启动方式的概念还很模糊,冷启动.热启动.温启动各种专业术语铺天盖地,使得许多用户眼花缭乱. 我们简单从定义上了解一下几种GPS启动的方式,GPS开机启动分为冷启动.温启动.热启动三种. ...
- Helm 安装 wordpress
1. 前置需要安装 storageclass 然后 安装helm 客户端 helm tiller 服务端 2. 设置 当前的位阿里云的 repo 3. 查找 wordpress的镜像 helm sea ...
- Study From DevOps 学习交流会议
1.今天下午参加了 软件集团的 爱城市的devops的沟通会议,了解到他们是通过bash的方式来执行jenkins的build以及创建 jenkins的 project 等内容.晚上回来简单实验了下. ...
- NABCD模型
下面是我对我们团队实现的程序的最终期待. 1.N(Need) 这里做了用户需求,所面向的用户虽然是所有英语学习群体,但是主要用户还是那群英文小说阅读者,即希望通过英文小说的阅读来提升单词量的人群. 1 ...
- pgm3
这部分主要讨论了一些概念性的东西.一个是常用的 local probabilistic models,一个是如何用 template-based representation. 这部分主要是一些概念, ...
- BZOJ2324 ZJOI2011营救皮卡丘(floyd+上下界费用流)
虽然不一定每次都是由编号小的点向编号大的走,但一个人摧毁的顺序一定是从编号小的到编号大的.那么在摧毁据点x的过程中,其只能经过编号小于x的点.并且这样一定合法,因为可以控制其他人先去摧毁所经过的点.那 ...
- BZOJ2169 连边(动态规划)
令f[i][j]表示连i条边时奇点个数为j的方案数,转移时讨论两奇点相连.一奇一偶相连.两偶点相连即可.注意这样会造成重边,那么算出恰好有一条重边的方案数并减掉.由于是有序地考虑每条边,每次还要除以i ...
- SSM 全局异常
转载: http://blog.csdn.net/m13321169565/article/details/7641978 废话不多,直接说重点. 一 创建异常拦截类 (这里将 webapi 和 ...