public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try{
GetAndPostExample sqlConn = new GetAndPostExample();
String path = "D:\\bems\\workspace\\flex_html\\src\\jspreport\\flexhtml.jasper";
File reportFile1 = new File(path);
JasperReport jasperReport = (JasperReport) JRLoader
.loadObject(reportFile1.getPath());
System.out.println(reportFile1.getPath());
if (!reportFile1.exists())
throw new JRRuntimeException("没找到合同模板路径");
Connection conn= sqlConn.getConnection();
JasperPrint jasperPrint = JasperFillManager.fillReport(
jasperReport, null, conn);
JRHtmlExporter exporter = new JRHtmlExporter();
response.setCharacterEncoding("GBK"); //处理中文乱码
PrintWriter writer=response.getWriter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_WRITER,writer );
exporter.setParameter(JRHtmlExporterParameter.IS_USING_IMAGES_TO_ALIGN, Boolean.FALSE);
exporter.setParameter(JRExporterParameter.CHARACTER_ENCODING, "GBK"); //处理中文乱码
exporter.exportReport();
writer.flush();
conn.close();
}catch (SQLException e1) {
e1.printStackTrace(); }
catch (JRException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
jasperreports 生成html
最新推荐文章于 2025-09-21 10:01:16 发布
本文介绍如何使用JasperReports从指定的.jasper文件生成HTML格式的报告,并通过Servlet将报告内容返回给客户端浏览器。该过程涉及加载报告模板、连接数据库、填充报告数据以及设置输出格式。
2722

被折叠的 条评论
为什么被折叠?



