java poi导出excel response.setHeader设置导出文件名抓包不合法及处理导出文件名为action方法名

时间:2018-07-12 13:21:55   收藏:0   阅读:2124

问题出现1:

spring MVC 框架下使用poi导出excel,设置导出文件名:response.setHeader("Content-Disposition", "attachment;filename=" +sourceId+"_"+dateString+".xls");

该方法进行抓包测试时,显示BUG url不合法。

解决办法:对 "attachment;filename=" +sourceId+"_"+dateString+".xls" 进行String fileNmae = URLEncoder.encode("attachment;filename="+sourceId+"_"+dateString+".xls",StandardCharsets.UTF_8.displayName()); 再response.setHeader("Content-Disposition", fileNmae);

 

但是出现新的问题2:poi导出excel时,导出文件名为action 方法名。

解决办法:使用 new String(byte[],"utf-8");编码

String fileName = "attachment;filename="+sourceId+"_"+dateString+".xls";
response.setHeader("Content-Disposition", new String(fileName.getBytes(), "utf-8"));

 

最终解决:抓包测试通过。

 

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!