簡體   English   中英

JSF下載並轉發到結果頁面

[英]JSF download and forward to a result page

我正在使用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();

您可以遵循以下條件之一:

  1. 選項1

    一世。 將用戶重定向到“結果”頁面

    ii。 向用戶顯示下載按鈕 ,單擊此按鈕后,打開一個新窗口,其中將顯示/下載PDF。

  2. 選項2

    一世。 將用戶重定向到“結果”頁面

    ii。 結果頁面加載后,使用javascript / jQuery發送請求以打開一個新窗口,在該窗口中將顯示/下載PDF。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM