jsp页面输出excel文件乱码解决方案

Jsp调出excel文件需要注意设置,否则有乱码。

 request.setCharacterEncoding("utf-8");

response.setHeader( "Pragma ","public");

response.setHeader( "Cache-Control", "must-revalidate, post-check=0, pre-check=0 ");

response.addHeader( "Cache-Control", "public ");

String filedisplay =URLEncoder.encode("商户交易统计报表.xls","UTF-8");

response.addHeader("Content-Disposition","attachment; filename="+filedisplay);

/*response.setContentType("application/vnd.ms-excel.numberformat:@;charset=GBK");  */

response.setContentType("application/vnd.ms-excel;charset=GBK");

微软的exel默认的编码方式的gb2312,这样汉字一定是乱码关键在你输出文字的时候需要设置charset=GBK


你可能感兴趣的:(jsp页面输出excel文件乱码解决方案)