一般情况下,大家都是这样:
fileName = (fileName, "UTF-8"); (); ("Content-disposition", "attachment;filename=" + fileName); ("application/octet-stream; charset=UTF-8"); (inputStream, ());
其实乱码就是乱在;filename=" + fileName这里,对文件名的编码设定上。
使用(filepath,"UTF-8")虽然可以解决在提示下载框中正确显示汉字文件名的问题,并且在选择保存,然后打开的情况下,文件名称也可以正确的显示。
但是在提示下载框中,选择直接打开,则文件名称变成了类似“%E7%BB%99%E7%94%A8%E6%88%B7%E6%8F%90%E4%BE%9B%E7%9A%84%E4%B8%8B%E8%BD%BD%E6%96%87%E4%BB%B6%E5%90%8D”的样子。
为了解决这个问题,百度了好久,是这样的
String downloadfile = new String(("gb2312"),"iso8859-1");
("Content-Disposition","attachment;filename=" + downloadfile );
还有这样
String userAgent = ("User-Agent");
String formFileName = "员工表.xls";
// 针对IE或者以IE为内核的浏览器:
if (("MSIE") || ("Trident")) {
formFileName = (formFileName, "UTF-8");
} else {
// 非IE浏览器的处理:
formFileName = new String(("UTF-8"), "ISO-8859-1");
}
("Content-disposition",("attachment; filename=\"%s\"", formFileName));
("multipart/form-data");
("UTF-8");
发现都不能解决问题,不懈努力,崩溃边缘,最终解决
fileName = (fileName, "UTF-8"); (); // fileName后面设置编码格式是重点 ("Content-disposition", "attachment;filename="+fileName+";"+"filename*=utf-8''"+fileName); ("application/octet-stream; charset=UTF-8"); (inputStream, ());
完美解决!!!