解决Java POI 导出Excel时文件名中文乱码,兼容浏览器

 

   String agent = request.getHeader("USER-AGENT").toLowerCase();
   response.setContentType("application/vnd.ms-excel");
   String fileName = "文件名";
   String codedFileName = java.net.URLEncoder.encode(fileName, "UTF-8");
   if (agent.contains("firefox")) {
           response.setCharacterEncoding("utf-8");
           response.setHeader("content-disposition", "attachment;filename=" + new String(fileName.getBytes(), "ISO8859-1") + ".xls" );
  } else {
          response.setHeader("content-disposition", "attachment;filename=" + codedFileName + ".xls");
   }

posted @ 2018-12-07 20:09  程序员小明1024  阅读(8529)  评论(0编辑  收藏  举报