我正在使用PrimeFaces。
我有一个包含命令链接 pdf 生成的数据表
当我单击此链接时,我想在新浏览器中打开pdf 。
我的生成报告代码为PDF:
HttpServletResponse response = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse();
String reportPath = FacesContext.getCurrentInstance().getExternalContext().getRealPath("/report/personReport.jrxml");
JasperDesign jasperDesign = JRXmlLoader.load(reportPath);
JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
ArrayList<PersonReportBean> arrayList = new ArrayList<PersonReportBean>();
arrayList.add(bean); // here bean populate with all data
JRBeanCollectionDataSource collectionDataSource = new JRBeanCollectionDataSource(arrayList);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, new HashMap<String, Object>(), collectionDataSource);
response.setContentType("application/pdf");
JRPdfExporter exporter = new JRPdfExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, response.getOutputStream());
exporter.exportReport();
FacesContext.getCurrentInstance().responseComplete();