spring mvc 模板下載
来源:互联网 发布:js this指向问题 编辑:程序博客网 时间:2024/06/12 23:47
@RequestMapping(value = "/download", method = RequestMethod.GET)
public void download(HttpServletRequest request, HttpServletResponse response, HttpSession session) throws Exception {
try {
String tempPath = "/template/import.txt";
String path = session.getServletContext().getRealPath("/");
path = new String(path.getBytes("ISO-8859-1"), "UTF-8");
path = path.replace("\\\\", "/");
File file = new File(path + tempPath);
if (!file.isFile() || !file.exists() || file.isDirectory()) {
throw new RuntimeException("下載的文件路徑或文件不存在!");
}
response.setContentType("octets/stream");
response.setContentLength((int) file.length());
response.addHeader("Content-Disposition", "attachment;filename=" + file.getName());
FileInputStream fis = new FileInputStream(file);
BufferedInputStream buff = new BufferedInputStream(fis);
byte b[] = new byte[1024];
long k = 0;
OutputStream out = response.getOutputStream();
while (k < file.length()) {
int j = buff.read(b, 0, 1024);
k += j;
out.write(b, 0, j);
}
out.flush();
buff.close();
out.close();
} catch (Exception e) {
logger.error(ExceptionUtils.getStackTrace(e));
throw new RuntimeException(e);
}
}
0 0
- spring mvc 模板下載
- spring mvc 使用Freemarker模板
- spring mvc 集成velocity模板
- Spring MVC + Mybatis 配置文件模板
- spring mvc 配置 velocity 模板
- spring mvc 配置 Mabatis 模板
- Spring MVC Velocity模板引擎
- spring mvc 集成freemarker模板
- spring mvc 集成velocity模板
- Spring mvc详解 (下)
- Spring MVC(下)
- Spring mvc详解 (下)
- Spring mvc 用FreeMarker模板化
- Spring MVC : Java模板引擎 Thymeleaf
- Spring MVC中使用Thymeleaf模板引擎
- Thymeleaf模板与Spring MVC集成
- Eclipse下搭建Spring MVC
- Spring MVC 下加入Tiles2
- UIPickView常用操作
- Wireshark抓包工具使用教程以及常用抓包规则
- 转自zhchch VirtualBox虚拟机使用技巧
- BaseAdapter优化
- 从默认的 _id 字段中,取得时间信息
- spring mvc 模板下載
- Oracle dbms_flashback
- 解决ADT不显示javadoc An exception occurred while getting the javadoc
- Linux系统的命令别名功能
- Spring Web开发
- RTP/RTCP协议介绍
- 数据库事务必须具备的ACID特性
- Eclipse快捷键大全
- Linux shell操作mysql数据库深入解析