由于以前导出文件名都是一个数字串,一直没有在意这个名称的问题.才有现在的懵逼
修改前:
/** * 设置导出头部信息(xls格式) * * @param response * @param fileName */ public static void setResponseForXls(HttpServletResponse response, String fileName) throws UnsupportedEncodingException { response.setCharacterEncoding("utf-8"); response.setContentType("multipart/form-data"); response.setHeader("Content-Disposition", "attachment;fileName=" + fileName + ".xls"); }
修改后:
public static void setResponseForXls(HttpServletResponse response, String fileName) throws UnsupportedEncodingException { response.setCharacterEncoding("utf-8"); response.setContentType("multipart/form-data"); response.setHeader("Content-Disposition", "attachment;fileName=" + URLEncoder.encode(fileName , "UTF-8") + ".xls"); }
天真的以为有了response.setCharacterEncoding("utf-8");就OK了, 还得加个 URLEncoder.encode(fileName , "UTF-8");
来源:oschina
链接:https://my.oschina.net/watler/blog/3213344