ireport 和eclipse的整合导出
来源:互联网 发布:淘宝客服kpi考核 编辑:程序博客网 时间:2024/06/09 17:20
public String iReport(){
Map parameters = new HashMap();
HouseAndHouse info = this.getModel();
// parameters.put("NAME", "ff");
Connection conn = null;
ServletContext context = this.getSession().getServletContext();
String path = context.getRealPath("/") + "WEB-INF/page/houseAndHouse/report1.jasper";
try {
Class.forName("com.mysql.jdbc.Driver");
conn
=DriverManager.getConnection("jdbc:mysql://192.168.1.98:3306/framework?useUnicode=true&characterEncoding=utf8","framework","password");
File reportFile = new File(path);
File sourceFile = new File(reportFile.getPath());
JasperReport jasperReport = (JasperReport)JRLoader.loadObject(sourceFile);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters,conn);
File destFile = new File(context.getRealPath("/") + jasperPrint.getName() + ".html");
String destFileName = destFile.toString();
JRHtmlExporter exporter = new JRHtmlExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, destFileName);
exporter.setParameter(JRHtmlExporterParameter.IS_USING_IMAGES_TO_ALIGN, Boolean.FALSE);
exporter.setParameter(JRHtmlExporterParameter.BETWEEN_PAGES_HTML, "");
exporter.setParameter(JRExporterParameter.CHARACTER_ENCODING, "UTF-8"); //关键是此句
exporter.exportReport();
fileName = jasperPrint.getName() + ".html";
System.out.println(jasperPrint.getName());
conn.close();
}catch (Exception e) {
e.printStackTrace();
}
this.getRequest().setAttribute("fileName", fileName);
return "ireport";
}
这个方法是导出html页面的一个方法
public void ireportPDF(){
Map parameters = new HashMap();
HouseAndHouse info = this.getModel();
parameters.put("name", info.getName());
parameters.put("workUnit",info.getWorkUnit());
Connection conn = null;
ServletContext context = this.getSession().getServletContext();
String path = context.getRealPath("/") + "WEB-INF/page/houseAndHouse/report1.jasper";
try {
Class.forName("com.mysql.jdbc.Driver");
conn
=DriverManager.getConnection("jdbc:mysql://192.168.1.98:3306/framework?useUnicode=true&characterEncoding=utf8","framework","password");
File reportFile = new File(path);
System.out.println(reportFile.getPath()+"======");
byte[] bytes = JasperRunManager.runReportToPdf(reportFile.getPath(), parameters, conn);
// byte[] bytes = JasperRunManager.runReportToHtmlFile(reportFile.getPath(), parameters, conn);
this.getResponse().setContentType("application/pdf");
this.getResponse().setContentLength(bytes.length);
ServletOutputStream ouputStream = this.getResponse().getOutputStream();
ouputStream.write(bytes, 0, bytes.length);
ouputStream.flush();
ouputStream.close();
}catch (Exception e) {
e.printStackTrace();
}
}
这个方法是导出pdf的一个方法。
到官方下载了ireport3.6的版本,其实ireport编译用到的包是jasperreports-3.5.2.jar这个版本的,所以在我们的项目中要有这个包才能解析,也就是说ireport里的包和jasperreports-3.5.2.jar这个包的版本要一样才能解析成功,不然会报错。解析不了我们绘制好的test.jasper的报表文件。
在eclipse项目中,我只添加了如下四个包
- ireport 和eclipse的整合导出
- iReport 导出表格的方法
- ireport导出
- eclipse和tomcat的整合
- Tomcat和eclipse的整合
- Eclipse和Tomcat的整合
- Struts2 实现导出和下载的整合
- ireport、jasperreport 导出excel的java代码
- jasperreport和iReport的使用
- Jasperreports和iReport 的使用
- Jasperreports和iReport 的使用
- ireport和jasperReport的资料
- JasperReport和iReport的资源
- MOTO SDK模拟器和Eclipse的整合
- 【转】Tapestry5和Eclipse的整合
- Eclipse的安装和整合jdk7、Tomcat7
- Maven 和Eclipse的整合(6)
- iReport 和 Jasperreport整合开发web报表向导(1)
- suse linux
- 观点 Ubuntu将主导普通用户市场
- 千万别忽略:18个有用的人情世故!
- JAVA操作COOKIE
- mobile 目录的操作
- ireport 和eclipse的整合导出
- js实现页面跳转的几种方式
- IQueryable<T>绑定到Repeater,执行Repeater_ItemDataBound事件时,遇到的问题及解决办法
- C#注册表操作大全
- BIOS启动过程分析
- 弹出div层
- 软件测试
- SEO 学习笔记——PR值
- PowerPC上浮点和定点有可能并行做