jasperReport导出html乱码问题解决

最近因为项目的需要
        File reportFile = new
         File(getServlet().getServletConfig().getServletContext().getRealPath("/reports/cadreinfor_report.jasper"));
         
         if (!reportFile.exists()) throw new JRRuntimeException("FileWebappReport.jasper " +
                 "not found. The report design must be compiledfirst.");     
         
         File sourceFile = new File(reportFile.getPath());
         JasperReport jasperReport = (JasperReport)JRLoader.loadObject(sourceFile);         
         JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, new HashMap(), new JREmptyDataSource());
         File destFile = new File(sourceFile.getParent(), jasperPrint.getName() + ".html");
         String destFileName = destFile.toString();
         JRHtmlExporter exporter = new JRHtmlExporter();
         exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
         exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, destFileName);
         exporter.setParameter(JRExporterParameter.CHARACTER_ENCODING, "GB2312"); //关键是此句      
         exporter.exportReport();
         response.sendRedirect("/reports/cadreinfor_report.html");

你可能感兴趣的:(html,Excel)