1. 程式人生 > >SpringMVC生成Excel和PDF檔案時檔名亂碼的解決方案

SpringMVC生成Excel和PDF檔案時檔名亂碼的解決方案

解決下載的檔名為中文時的亂碼問題:

//將程式碼

response.setHeader("Content-Disposition", "attachment; filename="  + URLEncoder.encode(excelName, "UTF-8"));

//修改為

response.setHeader("Content-Disposition", "attachment;filename=" + new String(excelName.getBytes("gbk"),"ISO-8859-1"));