0
如何以彈出窗口的形式顯示打印預覽頁面?使用ADF的Jasper報告打印預覽頁面
我試着從網上的代碼,但它把我帶到另一個頁面。
HttpServletResponse response = getResponse();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
response.setHeader("Cache-Control", "max-age=0");
response.setContentType("application/pdf");
ServletContext context = getContext();
InputStream reportStream = context.getResourceAsStream("report-templates/TestReport.jasper");
if (reportStream == null) {
throw new NullPointerException("Input stream is null");
}
JasperReport jasperTemplate = (JasperReport)JRLoader.loadObject(reportStream);
jasperTemplate.setWhenNoDataType(WhenNoDataTypeEnum.ALL_SECTIONS_NO_DETAIL);
Connection conn = getConnection();
JasperPrint print = JasperFillManager.fillReport(jasperTemplate, record,conn);
JasperExportManager.exportReportToPdfStream(print, baos);
response.setContentLength(baos.size());
baos.writeTo(response.getOutputStream());
baos.close();
response.getOutputStream().flush();
FacesContext.getCurrentInstance().responseComplete();
我在這裏做了什麼改變?