spring mvc 下载
1、代码:
response.setContentType("application/msword;charset=GBK");
try {
response.setHeader("Content-Disposition", "attachment;fileName=" + new String(fileName.getBytes("GBK"),"iso-8859-1"));
} catch (UnsupportedEncodingException e1) {
logger.error("头文件格式转换异常", e1);
}
try {
URL file = new URL(filepath + usepath);
InputStream inputStream = file.openStream();
OutputStream os = response.getOutputStream();
byte[] b = new byte[2048];
int length;
while ((length = inputStream.read(b)) > 0) {
os.write(b, 0, length);
}
//关闭。
os.close();
inputStream.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
2、图片

spring mvc 下载的更多相关文章
- Spring MVC -- 下载文件
像图片或者HTML文件这样的静态资源,在浏览器中打开正确的URL即可下载,只要该资源是放在应用程序的目录下,或者放在应用程序目录的子目录下,而不是放在WEB-INF下,tomcat服务器就会将该资源发 ...
- spring MVC 下载文件(转)
springle MVC中如何下载文件呢? 比struts2 下载文件简单得多 先看例子: @ResponseBody @RequestMapping(value = "/download& ...
- spring mvc 下载文件链接
http://www.blogjava.net/paulwong/archive/2014/10/29/419177.html http://www.iteye.com/topic/1125784 h ...
- Spring mvc 下载文件处理
@RequestMapping(value = "downFile") public void downFile(HttpServletResponse response, Str ...
- Spring mvc下载文件java代码
/** * 下载模板文件 * @author cq */ @RequestMapping("/downloadExcel.do") public ResponseEntity< ...
- spring mvc 下载安装
https://repo.spring.io/webapp/#/artifacts/browse/tree/General/libs-release-local/org/springframework ...
- spring mvc 下载的时候中文文件名不显示
Headers.add("Content-Disposition", "attachment;filename=" + new String(file.getB ...
- 基于Spring Mvc实现的Excel文件上传下载
最近工作遇到一个需求,需要下载excel模板,编辑后上传解析存储到数据库.因此为了更好的理解公司框架,我就自己先用spring mvc实现了一个样例. 基础框架 之前曾经介绍过一个最简单的spring ...
- spring mvc 避免IE执行AJAX时,返回JSON出现下载文件
<!-- 避免IE执行AJAX时,返回JSON出现下载文件 --> <bean id="mappingJacksonHttpMessageConverter" c ...
随机推荐
- 02.OOP面向对象-1.面向对象介绍
1.面向对象编程介绍 面向对象(object-oriented ;简称: OO) 至今还没有统一的概念 我这里把它定义为: 按人们 认识客观世界的系统思维方式,采用基于对象(实体) 的概念建立模型,模 ...
- TCP协议和UDP协议
一:TCP(Transmission Control Protocol) 传输控制协议 TCP是主机对主机层的传输控制协议,提供可靠的连接服务,采用三次握手确认建立一个连接: 第一次握手:主机A发送 ...
- MSMQ如何设置事务特性
- [SharePoint2010开发入门经典]12、SPS2010安全管理
本章概要: 1.SPS中的用户授权 2.理解服务器场解决方案和沙箱解决方案的不同 3.理解表单验证和声明验证
- iOS推送 (百度推送)
近期在使用推送,所以与大家分享一下我所遇到的问题,与解决这个问题的方法.! 1.首先生成CertificateSigningRequest文件. 点击钥匙串訪问-->从证书颁发机构请求证书--& ...
- 技术总结--android篇(一)--MVC模式
先介绍下MVC模式:MVC全名是Model View Controller,是模型(model)-视图(view)-控制器(controller)的缩写,一种软件设计典范,用一种业务逻辑.数据.界面显 ...
- 使用从mysql中取数据
import MySQLdb conn=MySQLdb.connect(host="xx",user="xx",passwd="xx",db ...
- h5-登录
<html> <head> <meta http-equiv="Content-Type" content="text/html; char ...
- 一种比较高级的方法也可以修改windows为默认启动系统
运行: sudo mv /etc/grub.d/30_os-prober /etc/grub.d/06_os-probersudo update-grub
- Centos7 minimal 系列之NAT联网(一)
一.安装 参考:http://m.blog.csdn.net/qq_24879495/article/details/77838512 二.解决不能联网问题 打开网络共享中心,设置虚拟网卡 编辑虚拟机 ...