1个回答
展开全部
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
本回答被提问者和网友采纳
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询