我正在使用 JSF 2.1 和 Primefaces。当用户提交表单时,我的程序填写 PDF 文档并将其下载到用户计算机,然后我需要显示带有状态消息的新页面。我的代码下载填写的表单但不重定向到结果页面。
PDDocument document = PDDocument.load("C:/Backup/test.pdf");
PDDocumentCatalog docCatalog = document.getDocumentCatalog();
PDAcroForm acroForm = docCatalog.getAcroForm();
....
在这里填写文件..
FacesContext facesContext = FacesContext.getCurrentInstance();
ExternalContext externalContext = facesContext.getExternalContext();
HttpServletResponse response = (HttpServletResponse) externalContext.getResponse();
response.setHeader("Content-disposition", "attachment; filename=\"test.pdf\"");
response.setHeader("Refresh", "1; URL=result.xhtml");
BufferedOutputStream output = null;
output = new BufferedOutputStream(response.getOutputStream());
document.save(output);
output.close();
facesContext.responseComplete();