0

Internet Explorer 不会下载文件,只会出现字符。

仅 Microsoft Office 文件,例如(.doc、.xls、.docx)

这是我的代码:

*.jspx:

      <p:commandButton  actionListener="#{LicitacaoControl.download}" icon="ui-icon-circle-zoomin" title="Visualizar Arquivo" ajax="false">
           <f:param id="visualizar" name="visualizar" value="#{arquivo}" />
      </p:commandButton>

控制器.java

public void download(ActionEvent evt) {
    try {
        Arquivo arquivo = (Arquivo) UtilFaces.getValorParametro(evt, "visualizar");
        HttpServletResponse resp = UtilFaces.getResponse();
        resp.addHeader("Content-disposition", String.format("inline; filename=\"%s.%s\"", arquivo.getDescricao(), arquivo.getExtensao()));
        OutputStream out = resp.getOutputStream();
        out.write(arquivo.getDados());
        FacesContext facesContext = FacesContext.getCurrentInstance();
        out.close();
        facesContext.responseComplete();
    } catch (IOException e) {
        UtilFaces.addMensagemFaces(e);
    }
}
4

1 回答 1

0

对于下载,您应该使用Content-Disposition: attachment而不是Content-Disposition: inline. 内联显示文件与下载文件相反。

于 2013-10-18T21:20:16.097 回答