求大神帮忙,要求: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 很想要一个很好的答案或提示
- ¥15 扫描项目中发现AndroidOS.Agent、Android/SmsThief.LI!tr
- ¥15 怀疑手机被监控,请问怎么解决和防止
- ¥15 Qt下使用tcp获取数据的详细操作
- ¥15 idea右下角设置编码是灰色的
- ¥15 全志H618ROM新增分区
- ¥15 在grasshopper里DrawViewportWires更改预览后,禁用电池仍然显示
- ¥15 NAO机器人的录音程序保存问题
- ¥15 C#读写EXCEL文件,不同编译
- ¥15 MapReduce结果输出到HBase,一直连接不上MySQL