1.一开始文件名全是下横线__
经查询之后,添加了这行代码
response.setHeader("Content-Disposition",
"attachment;filename=" + URLEncoder.encode(homeworkname, "utf-8"))
2.下横线的问题解决了,但出现中文乱码,出现%%字符
再次查找之类,将上述的代码改成以下,解决乱码
response.setHeader("Content-Disposition", "attachment;filename="+ homeworkname +";filename*=utf-8''"+URLEncoder.encode(homeworkname,"UTF-8"));
除此之外,发现也可以用这种方法
response.setHeader("Content-Disposition",
"attachment;filename=" + new String(homeworkname.getBytes("utf-8"), "ISO8859-1"));
参考博客:
https://blog.csdn.net/erf_1012/article/details/101026526
版权声明:本文为weixin_42063820原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。