关于response.addHeader(“Content-Disposition”, “attachment;filename=” + fileName + “.xls”) Excel文件名称中文乱码
// 文件名称
String fileName =params.get("fileName");
response.setCharacterEncoding("UTF-8");
response.addHeader("Content-Disposition", "attachment;filename=" + fileName + ".xls");
response.setContentType("application/x-msdownload");
文件名称乱码
文件名发送给服务器的时候把中文转成ISO8859-1,此时非中文的形式。new String(fileName.getBytes(“UTF-8”),“ISO8859-1”),其中getBytes()方法默认UTF-8
// 文件名称
String fileName =params.get("fileName");
response.setCharacterEncoding("UTF-8");
response.addHeader("Content-Disposition", "attachment;filename=" + new String(fileName.getBytes("UTF-8"),"ISO8859-1") + ".xls");
response.setContentType("application/x-msdownload");
文件名正常显示
文件名发送给服务器的时候用URLEncoder编码,此时非中文的形式。URLEncoder.encode(fileName,“UTF-8”)
// 文件名称
String fileName =params.get("fileName");
response.setCharacterEncoding("UTF-8");
response.addHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName,"UTF-8") + ".xls");
response.setContentType("application/x-msdownload");
文件名正常显示
参考相关资料链接:https://blog.csdn.net/fanyuna/article/details/5568089