文件下载Content-Disposition中文乱码

 

String fileName = "中国.doc";
//方法1:
response.setHeader("Content-Disposition", "attachment; filename=" + java.net.URLEncoder.encode(fileName, "UTF-8"));

//方法2:使用指定编码,并告诉浏览器编码类型
response.setHeader("Content-Disposition", "attachment; filename*=UTF-8''" + URLEncoder.encode(fileName, "UTF-8");

//方法3:
response.setHeader("Content-Disposition", "attachment; filename=" + new String(fileName.getBytes("gb2312"), "ISO8859-1")); 

猜你喜欢

转载自blog.csdn.net/sikedaima/article/details/86604093