【发布时间】:2023-03-19 23:45:02
【问题描述】:
我正在使用 Primefaces 文件下载。当我第一次启动应用程序时,文件已下载,但每次按下下载按钮时,都会出现此错误:
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;
}
【问题讨论】:
标签: java jsf-2 primefaces