在導(dǎo)出前對(duì)名稱根據(jù)瀏覽器做下處理
public static void compatibleFileName(HttpServletRequest request, HttpServletResponse response, String excelname) throws UnsupportedEncodingException {
String agent = request.getHeader("USER-AGENT").toLowerCase();
response.setContentType("application/vnd.ms-excel");
String fileName = excelname;
String codedFileName = java.net.URLEncoder.encode(fileName, "UTF-8");
if (agent.contains("firefox")) {
response.setCharacterEncoding("utf-8");
response.setHeader("content-disposition", "attachment;filename=" + new String(fileName.getBytes(), "ISO8859-1") + ".xls");
} else {
response.setHeader("content-disposition", "attachment;filename=" + codedFileName + ".xls");
}
}