ireport只是一个设计工具,把它生成的.jasper文件放到项目中,然后在Action或servlet中进行处理。代码大概如下:
JRBeanCollectionDataSource dataSource = new JRBeanCollectionDataSource();
FileInputStream fis = new FileInputStream(new File("xxx.jasper"));
Map<String,Object> parameters = new HashMap<String,Object>();
JasperPrint jasperPrint = JasperFillManager.fillReport(fis, parameters, dataSource);
byte[] bytes = JasperExportManager.exportReportToPdf(jasperPrint);
//得到bytes就可以写入到文件中了