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!