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

// 下载模板
@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")); 

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