zoukankan      html  css  js  c++  java
  • 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")); 

  • 相关阅读:
    404、500、502等HTTP状态码介绍
    Linux系统信息查看命令
    SVN clean up 无法继续
    gitlab使用
    Git SSH Key 生成步骤
    gitlab 杂记
    JS函数
    MySQL基础
    WEB测试方法
    操作系统的发展史
  • 原文地址:https://www.cnblogs.com/cbdd/p/5595805.html
Copyright © 2011-2022 走看看