-
Notifications
You must be signed in to change notification settings - Fork 21
etmvc中进行上传和下载
shuzheng edited this page Aug 13, 2015
·
1 revision
et-mvc上传文件是对Commons-fileupload组件的封装,所以使用时需要引入commons-fileupload.jar, commons-io.jar, commons-logging.jar三个包。
上传文件的第一步就是象下面一样创建一个multipart/form-data表单:
<form action="<c:url value="/upload/doUpload"/>" method="POST" enctype="multipart/form-data">
<input type="file" name="file">
<input type="submit" value="提交">
</form>
然后编写控制器,定义上传的Action方法:
public class UploadController extends ApplicationController{
public String doUpload(MultipartFile file) throws Exception{
file.transferTo(new File("e:/temp/" + file.getOriginalFilename()));
return file.getOriginalFilename()+":"+file.getSize();
}
}
需要下载文件时,可以使用BinaryView,如下所示:
public BinaryView download() throws Exception{
BinaryView view = BinaryView.loadFromFile("e:/temp/arrow.gif");
view.setContentType("image/gif");
//view.setContentDisposition("attachment"); //下载
return view;
}
上传下载就介绍这些,看起来应该是比较简单的。
使用教程
- etmvc框架介绍
- Hello,World经典示例
- 关于etmvc的配置
- 理解并使用控制器
- Action方法和控制器环境
- 关于etmvc的视图
- 扩展etmvc的视图
- 利用etmvc中的模型绑定简化Action方法的编写
- ORM-ActiveRecord基础
- 利用etmvc编写用户管理小例子
- ActiveRecord中同时访问多个数据库
- ActiveRecord中的关联
- etmvc中进行上传和下载
- etmvc和extjs结合分页例子
- etmvc的过滤器基础
- ActiveRecord中集成spring
- ActiveRecord中使用事务
- etmvc中使用环绕过滤器
- ActiveRecord中的数据类型映射
- ActiveRecord中的回调方法
- etmvc框架中的插件
- etmvc框架对URL路由的支持
- etmvc中使用环绕过滤器处理异常
- etmvc中的国际化处理
- etmvc框架集成spring