读书人

poi 3.8 导出excel 乱码解决办法

发布时间: 2012-06-23 14:52:43 作者: rapoo

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();

读书人网 >J2EE开发

热点推荐