【问题标题】:Internet Explorer doesn't make file download, only characters appearInternet Explorer 不下载文件,只显示字符
【发布时间】:2013-10-17 17:44:52
【问题描述】:

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>

Controller.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);
    }
}

【问题讨论】:

    标签: java internet-explorer facescontext


    【解决方案1】:

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

    【讨论】:

    • 对.. 谢谢,但我想显示一个文件而不是下载。如何做到这一点?
    猜你喜欢
    • 2011-02-20
    • 2011-02-11
    • 2022-01-10
    • 1970-01-01
    • 2014-12-10
    • 2010-12-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多