CommandButton 不会从操作中返回附件(txt 文件)。我没有错误。只是什么都没发生。
Java代码:
FacesContext facesContext = FacesContext.getCurrentInstance();
HttpServletResponse response = (HttpServletResponse)facesContext.getExternalContext().getResponse();
response.setContentType("application/txt");
response.setHeader("Content-Disposition","attachment;filename=file.txt");
IOUtils.copy(new StringReader("TEST"), response.getOutputStream());
facesContext.responseComplete();
facesContext.renderResponse();
冰面 - jspx
<ice:commandButton
id="downloadBtn"
action="#{contentsBean.downloadAsZip}"
value="txt" partialSubmit="true" immediate = "true" >
</ice:commandButton>
我尝试使用commandButton,因为我不能使用ice:outputResource。