PDF:
(1)利用response的outputString輸出:
response.setContentType("application/pdf");
//對應報表里面的Field
JRBeanCollectionDataSource jrb=new JRBeanCollectionDataSource(List或Set集合);
//Map集合對應報表里面的Parameter
byte[] pdfs=JasperRunManager.runReportToPdf(Test.class.getResourceAsStream("heting.jasper"), Map集合, jrb);
response.getOutputStream().write(pdfs, 0, pdfs.length);
(2)
Map parameters=new HashMap();
parameters.put("today", new Date());
List<Users> users=Make.getList();
JRBeanCollectionDataSource jrb=new JRBeanCollectionDataSource(users);
JasperPrint jasperPrint =
JasperFillManager.fillReport(Test.class.getResourceAsStream("heting.jasper"), parameters, jrb
);
JRXlsExporter exporter = new JRXlsExporter();
response.reset();
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition", "attachment;filename=\"aa.xls\"");
exporter.setParameter(JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, Boolean.TRUE);
exporter.setParameter(JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET,Boolean.FALSE);
exporter.setParameter(JRXlsExporterParameter.IS_WHITE_PAGE_BACKGROUND, Boolean.FALSE);
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRExporterParameter.CHARACTER_ENCODING, "GBK");
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM,response.getOutputStream());

exporter.exportReport();
HTML:

JRBeanCollectionDataSource jrb=new JRBeanCollectionDataSource(users);
JasperPrint jasperPrint =
JasperFillManager.fillReport(Test.class.getResourceAsStream("heting.jasper"), parameters, jrb
);
JRHtmlExporter exporter = new JRHtmlExporter();
exporter.setParameter(JRHtmlExporterParameter.OUTPUT_FILE_NAME,ls_reportname+".htm");
exporter.setParameter(JRExporterParameter.CHARACTER_ENCODING, "GBK");
exporter.setParameter(JRHtmlExporterParameter.BETWEEN_PAGES_HTML, "<div style=\"page-break-after:always\"></div>");
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_WRITER, response.getOutputStream());
exporter.exportReport();
EXCEL
JRBeanCollectionDataSource jrb=new JRBeanCollectionDataSource(users);
JasperPrint jasperPrint =
JasperFillManager.fillReport(Test.class.getResourceAsStream("heting.jasper"), parameters, jrb
);
JRHtmlExporter exporter = new JRHtmlExporter();
response.reset();
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition", "attachment;filename=\"" + ls_reportname + ".xls\"");
exporter.setParameter(JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, Boolean.TRUE);
exporter.setParameter(JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET,Boolean.FALSE);
exporter.setParameter(JRXlsExporterParameter.IS_WHITE_PAGE_BACKGROUND, Boolean.FALSE);
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRExporterParameter.CHARACTER_ENCODING, "GBK");
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM,response.getOutputStream());
exporter.exportReport();
(1)利用response的outputString輸出:


//對應報表里面的Field
JRBeanCollectionDataSource jrb=new JRBeanCollectionDataSource(List或Set集合);
//Map集合對應報表里面的Parameter























JRBeanCollectionDataSource jrb=new JRBeanCollectionDataSource(users);



JRHtmlExporter exporter = new JRHtmlExporter();





exporter.exportReport();





JRHtmlExporter exporter = new JRHtmlExporter();









exporter.exportReport();
