0

Internet Explorer doesn't make file download, only characters appear.

Just Microsoft Office files for example (.doc,.xls,.docx)

This is my code:

*.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);
    }
}
Dave Chen
  • 10,887
  • 8
  • 39
  • 67

1 Answers1

0

For a download you should be using Content-Disposition: attachment rather than Content-Disposition: inline. Displaying a file inline is the opposite of downloading it.

Boann
  • 48,794
  • 16
  • 117
  • 146