解决火狐浏览器文件名空格出现+号

This commit is contained in:
leijun
2018-10-18 11:15:25 +08:00
parent bfaa681811
commit 5cb07b724c
2 changed files with 7 additions and 1 deletions

View File

@@ -1395,7 +1395,7 @@ public class ExportExcel {
public ExportExcel write(HttpServletResponse response, String fileName) throws IOException{
response.reset();
response.setContentType("application/octet-stream; charset=utf-8");
response.setHeader("Content-Disposition", "attachment; filename="+Encodes.urlEncode(fileName));
response.setHeader("Content-Disposition", "attachment; filename=\""+fileName+"\"");
write(response.getOutputStream());
return this;
}

View File

@@ -2,6 +2,7 @@ package com.nis.web.controller;
import java.beans.PropertyEditorSupport;
import java.io.IOException;
import java.lang.reflect.Field;
import java.net.URLEncoder;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
@@ -2237,6 +2238,11 @@ public class BaseController {
map.put("labels", labels);
String fileName = msgProp.getProperty(functionName, functionName)+"_"+DateUtils.getDate("yyyyMMddHHmmss")+".xlsx";
if(request.getHeader("User-Agent").toUpperCase().indexOf("MSIE")>0){
fileName = URLEncoder.encode(fileName, "UTF-8");
}else{
fileName = new String(fileName.getBytes("UTF-8"),"ISO8859-1");
}
new ExportExcel(msgProp,titleList,noExportMap,classMap,1).setDataList(msgProp,dataMap,map).write(response, fileName).dispose();
}
}