如果下载的文件名称包括空格、(、)、;、@、#、&
String newName = URLEncoder.encode(name, "UTF-8").replaceAll("\\+", "%20").replaceAll("%28", "\\(").replaceAll("%29", "\\)").replaceAll("%3B", ";").replaceAll("%40", "@").replaceAll("%23", "\\#").replaceAll("%26", "\\&");
如果下载的文件名称包括%20 chrome 浏览器回解析成空格
// response.setContentType("." + URLEncoder.encode((newName), "UTF-8") + "; charset=UTF-8");
response.setContentType(".dump9; charset=UTF-8");
if (browserType != null && browserType.equals("GOOGLE_CHROME")) {
response.setHeader("Content-disposition", "attachment; filename*=UTF-8''" + newName); //处理文件名包含%20 不转换成空格
} else {
response.setHeader("Content-disposition", "attachment; filename=" + newName);
}
//response.setContentType("application/x-msdownload;");
response.setContentType("application/dmp;");
response.setHeader("Cache-Control", "no-cache");
response.setHeader("Content-Length", String.valueOf(size));