Home > Java > JavaBase > body text

Solution to garbled file name when exporting excel using java

Release: 2019-12-04 09:23:34
Original
6586 people have browsed it

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

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!