MogliFS与spring mvc结合简单示例
一、MogliFS 与Spring结合配置请参照上文
二、上传页面
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <form action="${pageContext.request.contextPath}/file/upload" method="post" enctype="multipart/form-data">
file1:<input type="file" name="myFile"/>
<br>
file2:<input type="file" name="myFile"/>
<br>
<input type="submit" value="上传">
</form>
三、mvc的CommonsMultipartResolver解析器配置
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="maxUploadSize" value=""/>
</bean>
四、上传
@RequestMapping(value = "/upload", method = RequestMethod.POST)
public String upload(
HttpServletRequest request, @RequestParam(value = "myFile", required = false) MultipartFile[] files) {
try {
for(int i=;i<files.length;i++){
MultipartFile file=files[i]; if(StringUtils.isNotEmpty(file.getName()) && file.getSize() > ){ ...... MojiFile mf = moji.getFile("MyFileKey"+uuid); OutputStream out = null;
InputStream in = null;
try {
out = mf.getOutputStream();
in = file.getInputStream(); byte[] bs = new byte[];
while( in.read(bs) != -){
out.write(bs);
} out.flush();
} finally {
in.close();
out.close();
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return "success";
}
五、下载
@RequestMapping(value = "download", method = RequestMethod.GET)
public void download(HttpServletRequest request,
HttpServletResponse response, String fileName) throws Exception {
response.setContentType("text/html;charset=UTF-8");
request.setCharacterEncoding("UTF-8");
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
...... MojiFile mf = moji.getFile("MyFileKey" + uuid);
response.setHeader("Content-disposition", "attachment; filename="
+ new String(newFileName.getBytes("gb2312"), "ISO8859-1"));
response.setHeader("Content-Length", String.valueOf(mf.length()));
bis = new BufferedInputStream(mf.getInputStream());
bos = new BufferedOutputStream(response.getOutputStream());
byte[] buff = new byte[];
int bytesRead;
while (- != (bytesRead = bis.read(buff, , buff.length))) {
bos.write(buff, , bytesRead);
}
bis.close();
bos.close();
}
MogliFS与spring mvc结合简单示例的更多相关文章
- 用Spring MVC开发简单的Web应用程序
1 工具与环境 借助Eclipse4.3 + Maven3.0.3构建Java Web应用程序.使用Maven内置的servlet 容器jetty,不需手工集成Web服务器到Eclipse.还帮我们自 ...
- Spring MVC之简单入门
一.Spring MVC简介: 1.什么是MVC 模型-视图-控制器(MVC)是一个众所周知的以设计界面应用程序为基础的设计模式.它主要通过分离模型(Model).视图(View)及控制器(Contr ...
- Spring MVC - Hello World示例
以下示例演示如何使用Spring MVC框架编写一个简单的基于Web的Hello World应用程序.首先使用Eclipse IDE,并按照以下步骤使用Spring Web Framework开发一个 ...
- 用Spring MVC开发简单的Web应用
这个例子是来自于Gary Mak等人写的Spring攻略(第二版)第八章Spring @MVC中的一个例子,在此以学习为目的进行记录. 问题:想用Spring MVC开发一个简单的Web应用, 学习这 ...
- Spring MVC 入门教程示例 (一)
今天和大家分享下 Spring MVC 入门教程 首先还是从 HelloWorld web 工程开始 -------------------------- 1.首先创建一个Maven Web工程 ...
- 基于注解的Spring MVC的简单入门——简略版
网上关于此教程各种版本,太多太多了,因为我之前没搭过框架,最近带着两个实习生,为了帮他们搭框架,我只好...惭愧啊...基本原理的话各位自己了解下,表示我自己从来没研究过Spring的源码,所以工作了 ...
- spring mvc 注解入门示例
web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi=" ...
- spring boot thymeleaf简单示例
说实话,用起来很难受,但是人家官方推荐,咱得学 如果打成jar,这个就合适了,jsp需要容器支持 引入依赖 <dependency> <groupId>org.springfr ...
- JAVA入门[20]-Spring Data JPA简单示例
Spring 对 JPA 的支持已经非常强大,开发者只需关心核心业务逻辑的实现代码,无需过多关注 EntityManager 的创建.事务处理等 JPA 相关的处理.Spring Data JPA更是 ...
随机推荐
- JAVA SparkSQL初始和创建DataFrame的几种方式
建议参考SparkSQL官方文档:http://spark.apache.org/docs/latest/sql-programming-guide.html 一.前述 1.SparkSQ ...
- OpenJudge计算概论-最长单词2
/*======================================================================== 最长单词2 总时间限制: 1000ms 内存限制: ...
- Flex 布局的最简单表单
http://www.ruanyifeng.com/blog/2018/10/flexbox-form.html https://www.cnblogs.com/grt322/p/8531882.ht ...
- ISO/IEC 9899:2011 条款5——5.1.1 翻译环境
5.1.1 翻译环境 5.1.1.1程序结构 1.一个C程序不需要一次全被翻译完.程序的文本被保存在本国际标准中被称作为源文件(或预处理文件)的单元里.一个源文件连同所有通过指示符#include所包 ...
- osg HUD 背景图片设置
#ifdef _WIN32 #include <Windows.h> #endif // _WIN32 #include<iostream> #include <osgV ...
- PAT 甲级 1043 Is It a Binary Search Tree (25 分)(链表建树前序后序遍历)*不会用链表建树 *看不懂题
1043 Is It a Binary Search Tree (25 分) A Binary Search Tree (BST) is recursively defined as a bina ...
- ElasticSearch文档删除字段
https://www.cnblogs.com/ljhdo/archive/2017/03/24/4885796.html
- <configSections> 位置引起的错误
今天在配置一个项目的时候,花了挺长时间配置完成,然后一启动项目,懵了,启动报错:错误显示 Configuration Error Description: An error occurred duri ...
- 在Electron运行的页面使用CSS的calc导致应用卡死
这几天发现运行在我们开发的Electron里面的网页有部分应用点击访问就会卡死,通过排除法定位到使用了CSS的calc方法,如下: <el-table height="calc(100 ...
- Egret入门学习日记 --- 第三篇 (书中 3.4 内容)
第三篇 (书中 3.4 内容) 今天还是要把昨天项目运行后,EXML文件里的界面没有出现的问题解决了才行. 去了群里,没人回.去了官网看文档,看不懂. 不过倒是看到了一个好东西: 还挺便宜啊,一个月要 ...