我正在使用Primefaces fileDownload。當我第一次啓動該文件被下載的應用程序,但然後每次我按下下載按鈕,出現此錯誤:Primefaces fileDownload - getOutputStream()已被調用此響應
java.lang.IllegalStateException: getOutputStream() has already been called for this response
我的XHTML代碼:
<p:commandButton value="Download" ajax="true">
<p:fileDownload value="#{fileDownloadController.file}" />
</p:commandButton>
我的Java代碼:
private StreamedContent file;
public FileDownloadController() {
InputStream stream = null;
try {
stream = FacesContext.getCurrentInstance().getExternalContext().getResourceAsStream("/Enastr1.txt");
file = new DefaultStreamedContent(stream, "txt", "Downloaded_Enastr1");
} catch (Exception ex) {
Logger.getLogger(FileDownloadController.class.getName()).log(Level.SEVERE, null, ex);
} finally {
}
}
public StreamedContent getFile() {
return file;
}
public void setFile(StreamedContent file) {
this.file = file;
}
你是一個保佑! – spauny
請你能舉出第二個解決方案的例子。 – Sarz