//在jsp页面中 <% //new 一个 ArrayList集合 把 要显示的JasperPrint 放进去 ArrayList jasperPrintList = new ArrayList(); JasperPrint jasperPrintArr = JasperFillManager.fillReport ("reportAva.jasper", new HashMap(), new AvaDataSource()); JasperPrint jasperPrintCpu = JasperFillManager.fillReport ("cpuIReport.jasper", new HashMap(), new CpuDatasource()); JasperPrint jasperPrintFan = JasperFillManager.fillReport ("FanReport.jasper", new HashMap(), new FanDatasource()); JasperPrint jasperPrintLinAva = JasperFillManager.fillReport ("LinAvaReport1.jasper", new HashMap(), new LinDatasource()); JasperPrint jasperPrintLinDis = JasperFillManager.fillReport ("LinDisReport.jasper", new HashMap(), new LinDisDatasource()); JasperPrint jasperPrintMemory = JasperFillManager.fillReport ("MemoryReport.jasper", new HashMap(), new MemoryDatasource()); JasperPrint jasperPrintPower = JasperFillManager.fillReport ("PowerReport.jasper", new HashMap(), new powerDatasource()); JasperPrint jasperPrintTpt = JasperFillManager.fillReport ("TptReport.jasper", new HashMap(), new TptDatasource()); JasperPrint jasperPrintVol = JasperFillManager.fillReport ("VolReport.jasper", new HashMap(), new VolDatasource()); JasperPrint jasperPrintTile = JasperFillManager.fillReport ("Title_report.jasper", new HashMap(), new VolDatasource()); jasperPrintList.add(jasperPrintTile); jasperPrintList.add(jasperPrintArr); jasperPrintList.add(jasperPrintCpu); jasperPrintList.add(jasperPrintLinAva); jasperPrintList.add(jasperPrintMemory); jasperPrintList.add(jasperPrintLinDis); jasperPrintList.add(jasperPrintFan); jasperPrintList.add(jasperPrintVol); jasperPrintList.add(jasperPrintPower); jasperPrintList.add(jasperPrintTpt); //报表编译之后生成的.jasper 文件的存放位置 //传递报表中用到的参数值 Map parameters = new HashMap(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); JRPdfExporter exporter = new JRPdfExporter(); exporter.setParameter(JRExporterParameter.JASPER_PRINT_LIST,jasperPrintList); exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, baos); exporter.exportReport(); byte[] bytes= baos.toByteArray();//得到这个流 System.out.println("---------Jasper end-------------"); response.setContentType("application/pdf"); response.setContentLength(bytes.length); ServletOutputStream ouputStream = response.getOutputStream(); ouputStream.write(bytes, 0, bytes.length); ouputStream.flush(); ouputStream.close(); %> <html> <head> </head> <body> </body> </html>
转载于good_dou的专栏http://hi.csdn.net/link.php?url=http://blog.csdn.net%2Fgood_dou