String userAgent = request.getHeader(“User-Agent”).toLowerCase();
if(userAgent.contains(“safari”) && !userAgent.contains(“chrome”)){
//处理safari的乱码问题
byte[] bytesName = fileName.getBytes(“UTF-8”);
fileName = new String(bytesName, “ISO-8859-1”);
response.setHeader(“Content-Disposition”, “attachment;filename=/”” + fileName + “/””);
}else{
if (“zh”.equals(language)) { //中文状态下转码 英文不用转码 用 iso-8859-1 转码文件名称如果包含特殊符号下载 会报错
fileName = URLEncoder.encode(fileName, “UTF-8”);
}
response.setHeader(“content-disposition”, “attachment;fileName=”+ fileName);
}
原创文章,作者:Maggie-Hunter,如若转载,请注明出处:https://blog.ytso.com/17398.html