在controller中进行代码编写;

    @RequestMapping("/download")
public ResponseEntity<byte[]> download(HttpServletRequest req)
throws IOException {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
//解决中文名称乱码问题
String filename = new String("你好.xls".getBytes("UTF-8"), "iso-8859-1");
headers.setContentDispositionFormData("attachement", filename);
String realpath = req.getSession().getServletContext()
.getRealPath("/resources/upload/");
String pathname = realpath + File.separator + "123";
File file = new File(pathname);
return new ResponseEntity<byte[]>(FileUtils.readFileToByteArray(file),
headers, HttpStatus.CREATED);
}

spring mvc 文件下载的更多相关文章

  1. Spring MVC文件下载

    方案一: // 文件下载 @RequestMapping(value = "/downloadFile") public ResponseEntity<byte[]> ...

  2. spring mvc 文件下载 get请求解决中文乱码问题

    方案简写,自己或有些基础的可以看懂,因为没时间写的那么详细 方案1 spring mvc解决get请求中文乱码问题, 在tamcat中server.xml文件 URIEncoding="UT ...

  3. Spring MVC 文件下载时候 发现IE不支持

    @RequestMapping("download") public ResponseEntity<byte[]> download(Long fileKey) thr ...

  4. Spring MVC 的文件下载

    在看Spring MVC文件下载之前请先看Spring MVC文件上传 地址:http://www.cnblogs.com/dj-blog/p/7535101.html 文件下载比较简单,在超链接中指 ...

  5. Spring MVC教程——检视阅读

    Spring MVC教程--检视阅读 参考 Spring MVC教程--一点--蓝本 Spring MVC教程--c语言中午网--3.0版本太老了 Spring MVC教程--易百--4.0版本不是通 ...

  6. Spring MVC 文件上传 & 文件下载

    索引: 开源Spring解决方案--lm.solution 参看代码 GitHub: pom.xml WebConfig.java index.jsp upload.jsp FileUploadCon ...

  7. spring mvc的excel报表文件下载时流的冲突解决

    在jsp或者在servlet中有时要用到 response.getOutputStream(),但是此时会在后台报这个错误java.lang.IllegalStateException: getOut ...

  8. Http请求中Content-Type讲解以及在Spring MVC中的应用

    引言: 在Http请求中,我们每天都在使用Content-type来指定不同格式的请求信息,但是却很少有人去全面了解content-type中允许的值有多少,这里将讲解Content-Type的可用值 ...

  9. Spring MVC 学习总结(三)——请求处理方法Action详解

    Spring MVC中每个控制器中可以定义多个请求处理方法,我们把这种请求处理方法简称为Action,每个请求处理方法可以有多个不同的参数,以及一个多种类型的返回结果. 一.Action参数类型 如果 ...

随机推荐

  1. ural1439 Battle with You-Know-Who

    Battle with You-Know-Who Time limit: 2.0 secondMemory limit: 64 MB Rooms of the Ministry of Magic ar ...

  2. jquery.proxy的四种使用场景及疑问

    作者:zccst 其实只有两种使用方式,只不过每一种又细分是否传参. 先给一段HTML,后面会用来测试: <p><button id="test">Test ...

  3. Spring整合Hibernate--声明式事务管理

    Spring指定datasource 1. 新建jdbc.properties文件: jdbc.driverClassName=com.mysql.jdbc.Driver jdbc.url=jdbc: ...

  4. 控制流之continue

    continue语句continue语句被用来告诉Python跳过当前循环块中的剩余语句,然后 继续 进行下一轮循环.使用continue语句~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ...

  5. URL与String转换

    NSString *str = @"www.baidu.com"; NSURL *URL = [NSURL URLWithString:str];  //string>url ...

  6. iOS 发布流程 分类: ios相关 app相关 2015-05-22 14:50 186人阅读 评论(0) 收藏

    1.登陆苹果开发者中心http://developer.apple.com(99美元账号) 2.进入itunes connect 3.选择Manage Your Apps 4.选择Add New Ap ...

  7. realvnc的卸载

    我安装了realvnc5.3.2后,采用如下方式卸载: (1)用如下命令查询当前安装的realvnc包的全名: rpm -qa realvnc-vnc-server (2) rpm -e 查询到的安装 ...

  8. Thinking in scala (4)----阶乘与尾递归

    code1: object factorial{ def main(args:Array[String])={ println(factorial(args(0).toInt)) } def fact ...

  9. 外部SRAM实验,让STM32的外部SRAM操作跟内部SRAM一样(转)

    源:外部SRAM实验,让STM32的外部SRAM操作跟内部SRAM一样 前几天看到开源电子论坛(openedv.com)有人在问这个问题,我特意去做了这个实验,这样用外部SRAM就跟用内部SRAM一样 ...

  10. IOS开发-OC学习-Foundation框架练习

    OC语言Foundation框架中字典.字符串.数组的应用: NSString *string = @"China|Usa|France"; NSArray *array = [s ...