jasperreports 生成html

论坛 期权论坛 脚本     
已经匿名di用户   2022-5-29 18:50   1512   0

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();
}
}
分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:81
帖子:4969
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP