首页 > 其他 > 详细

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

时间:2016-06-18 11:20:03      阅读:286      评论: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)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!