0

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。

4

1 回答 1

0

您可以使用 ice:outputResource 作为网站上的隐形按钮。当用户单击命令按钮时,您可以使用 javaScript 在 ice:outputResource 上引发类似“onClick”的内容。

于 2016-08-25T16:52:55.527 回答