求大神帮忙,要求:Java,写一个打印报表的功能!我已经用iReport制作了报表生成了 .jrxml文件,我设置的数据源是 Database JDBC,数据已经使用SQL语句加载进去了,现在只要通过java调用这个文件进行编译打印就可以了,还要实现一下预览,不知道代码怎么编写,拜托大神帮忙,非常感谢!
java 打印报表问题(客户端打印)
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
1条回答 默认 最新
- threenewbee 2018-07-08 15:44关注
是在jsp里面用么?这里有个生成网页预览的代码;
Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--> 1 <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ page import="java.io.*, net.sf.jasperreports.engine.*, net.sf.jasperreports.engine.util.*, java.util.*,java.sql.*, net.sf.jasperreports.engine.export.*"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> </head> <body> <% File reportFile = new File(application .getRealPath("jasper/Test2.jasper")); JasperReport jasperReport = (JasperReport) JRLoader .loadObject(reportFile.getPath()); Map parameters = new HashMap(); parameters.put("para1", "AAA"); Class.forName("com.mysql.jdbc.Driver"); Connection conn = DriverManager.getConnection( "jdbc:mysql://localhost:3306/phpcms", "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(); %> </body> </html>
ref: https://www.cnblogs.com/micki/archive/2010/05/17/1737592.html
解决 无用评论 打赏 举报
悬赏问题
- ¥15 如何在scanpy上做差异基因和通路富集?
- ¥20 关于#硬件工程#的问题,请各位专家解答!
- ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
- ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
- ¥30 截图中的mathematics程序转换成matlab
- ¥15 动力学代码报错,维度不匹配
- ¥15 Power query添加列问题
- ¥50 Kubernetes&Fission&Eleasticsearch
- ¥15 報錯:Person is not mapped,如何解決?
- ¥15 c++头文件不能识别CDialog