struts2整合poi导出excel文件名乱码或不显示解决办法

时间:2021-10-26 09:20:08

struts配置文件:

<result name="excel"  type="stream">
                <param name="contentType">application/vnd.ms-excel,charset=ISO8859-1</param>  
                <param name="contentDisposition">attachment;filename="${downloadFileName}"</param>  
                <param name="bufferSize">1024</param>
                <param name="inputName">excelFile</param>
            </result>

1、中文文件名不显示:

downloadFileName=“中文abc.xls”;

这时候导出的excel,文件名是abc.xls,没有中文

2、IE乱码,火狐和谷歌显示正常:

downloadFileName = new String(URLDecoder.decode(fileName,"UTF-8").getBytes(), "ISO8859-1");

3、完全解决方案:

String fileName="中文abc.xls";

downloadFileName=new String(fileName.getBytes("gb2312"), "iso8859-1");