首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2EE开发 >

poi 3.8 导出excel 乱码解决办法

2012-06-23 
poi 3.8 导出excel 乱码在weblogic下 poi3.8 导出excel数据,中文会成乱码但在tomcat下是正常的,各位求解,

poi 3.8 导出excel 乱码
在weblogic下 poi3.8 导出excel数据,中文会成乱码
但在tomcat下是正常的,各位求解,谢谢!

[解决办法]
这是我昨天刚解决的问题,看对你有没有帮助

Java code
 try {           // fileName = new String(fileName.getBytes("UTF-8"), "UTF-8");           //if (request.getHeader("User-Agent").toLowerCase().indexOf("firefox") > 0)             fileName = new String(fileName.getBytes("UTF-8"), "ISO8859-1");//firefox浏览器                //                else ////                    if (request.getHeader("User-Agent").toUpperCase().indexOf("MSIE") > 0)////                    fileName = URLEncoder.encode(fileName, "UTF-8");//IE浏览器         } catch (UnsupportedEncodingException e) {            // should no happen        }        System.out.println(fileName);        response.reset();        response.setContentType("application/msexcel;charset=UTF-8");        response.setHeader("Content-disposition", "attachment;filename= " + fileName);    }
[解决办法]
String downloadName = "表名.xls";
downloadName = new String(downloadName.getBytes(), "ISO8859-1");
response.setHeader("Content-disposition", "attachment;filename=" + downloadName);
response.setContentType("application/x-download");

ServletOutputStream servletOutputStream = response.getOutputStream();
wb.write(servletOutputStream);
servletOutputStream.flush();
servletOutputStream.close();

热点排行