response.addHeader文件名中文乱码的问题
我一开始用的是这个:
response.setCharacterEncoding("UTF-8");
response.setContentType("application/xlsx");// 设置输出格式头信息
response.setHeader("Content-Disposition", "attachment; filename="+fileName+".pdf"+";target=_blank");
下载一个PDF文件用中文名表示,但是下载后发现只有下划线,然后我去百度找了好久,终于被我琢磨出来了
改:
// response.setCharacterEncoding("UTF-8");
response.setContentType("application/xlsx");// 设置输出格式头信息
// response.setHeader("Content-Disposition", "attachment; filename="+fileName+".xlsx"+";target=_blank");
response.addHeader("Content-Disposition", "attachment; filename=" +new String(fileName.getBytes("utf-8"),"iso-8859-1")+ ".xlsx");