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);
}
java 下载文件中文名称转码
最新推荐文章于 2023-11-28 19:31:08 发布