我有以下命令链接代码:
<h:commandLink id="number1" immediate="true" value="Downloadfile" action="#{businessBean.downloadFileAsZip}">
和downloadFileAsZip方法:
FacesContext context = FacesContext.getCurrentInstance();
ExternalContext eContext = context.getExternalContext();
HttpServletResponse response = (HttpServletResponse) eContext.getResponse();
response.reset();
response.setContentType("application/zip");
response.setCharacterEncoding("UTF-8");
try (ServletOutputStream out = response.getOutputStream()) {
try (ZipOutputStream zOut = new ZipOutputStream(out, Charset.forName("cp866"))) {
byte[] data = ...some data....;
zOut.putNextEntry(new ZipEntry("some file"));
zOut.write(data);
zOut.closeEntry();
zOut.flush();
}
}
facesContext.responseComplete();
我猜不可能在同一响应中下载文件并重新呈现页面组件。有没有可能的解决方案,当点击按钮时,不仅下载文件,而且更新具有特定 id 的 jsf 组件?