码迷,mamicode.com
首页 > 其他好文 > 详细

ie 导出不行,不兼容问题,或只出现后缀文件无法识别

时间:2016-06-18 11:21:57      阅读:1044      评论:0      收藏:0      [点我收藏+]

标签:

// 下载模板
@RequestMapping("/download")
@ResponseBody
public ResponseEntity<byte[]> download(HttpServletRequest request)throws IOException {

String path="mouldmb.xls";
File file = new ClassPathResource(path).getFile();// path是根据日志路径和文件名拼接出来的
String filename="客户资料导入模板"+".xls";
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
headers.setContentDispositionFormData("attachment", new String(filename.getBytes("utf-8"),"iso8859-1"));
return new ResponseEntity<byte[]>(FileUtils.readFileToByteArray(file),headers, HttpStatus.CREATED); //状态码是201,ie10,11不识别  改为HttpStatus.OK  但名称会乱码
}

可能是与操作系统有关系

将headers.setContentDispositionFormData("attachment", new String(filename.getBytes("utf-8"),"iso8859-1")); 

改为

headers.setContentDispositionFormData("attachment", new String(filename.getBytes("GBK"),"iso8859-1")); 

ie 导出不行,不兼容问题,或只出现后缀文件无法识别

标签:

原文地址:http://www.cnblogs.com/cbdd/p/5595805.html

(0)
(2)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!