Home  >  Article  >  Java  >  Solution to garbled file name when exporting excel using java

Solution to garbled file name when exporting excel using java

尚
Original
2019-12-04 09:23:346623browse

Solution to garbled file name when exporting excel using java

java Example of a method to solve garbled file names when exporting Excel: (Recommended: java video tutorial)

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");
   }

encode() method to specify The encoding format of the encoded string.

For more java knowledge, please pay attention to the java basic tutorial column.

The above is the detailed content of Solution to garbled file name when exporting excel using java. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn