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:
EXCEL