Ireport怎么将做成的报表通过JSP页面调用并输出打印?
展开全部
File reportFile = new File(application.getRealPath("report/test.jasper"));
JasperReport jasperReport = (JasperReport) JRLoader.loadObject(reportFile.getPath());
Map parameters = new HashMap();
String str0 = request.getParameter("time");
String str1 = request.getParameter("no");
String str2 = request.getParameter("name");
parameters.put("time", str0);
parameters.put("no", str1);
parameters.put("name", str2);
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root", "root");
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, conn);
JRHtmlExporter exporter = new JRHtmlExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_WRITER, out);
exporter.setParameter(JRHtmlExporterParameter.IS_USING_IMAGES_TO_ALIGN,Boolean.FALSE);
exporter.exportReport();
out.flush();
conn.close();
out.clear();
out = pageContext.pushBody();
JasperReport jasperReport = (JasperReport) JRLoader.loadObject(reportFile.getPath());
Map parameters = new HashMap();
String str0 = request.getParameter("time");
String str1 = request.getParameter("no");
String str2 = request.getParameter("name");
parameters.put("time", str0);
parameters.put("no", str1);
parameters.put("name", str2);
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root", "root");
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, conn);
JRHtmlExporter exporter = new JRHtmlExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_WRITER, out);
exporter.setParameter(JRHtmlExporterParameter.IS_USING_IMAGES_TO_ALIGN,Boolean.FALSE);
exporter.exportReport();
out.flush();
conn.close();
out.clear();
out = pageContext.pushBody();
更多追问追答
追答
生成test.jasper的时候,一般选择PDF格式,在客户端安装pdf
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询