Set the http response header in order to please IE when downloading file over https. - Java JSF

Java examples for JSF:FacesContext

Description

Set the http response header in order to please IE when downloading file over https.

Demo Code


import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;

public class Main{
    /**/*  w  w w .j ava 2 s. c  o  m*/
     * Set the http response header in order to please IE when downloading file over https.
     * see http://stackoverflow.com/questions/1918840/downloading-an-excel-file-over-https-to-ie-from-a-j2ee-application
     */
    public static void forceResponseHeaderForDownload() {
        FacesContext fc = FacesContext.getCurrentInstance();
        ExternalContext ec = fc.getExternalContext();
        ec.setResponseCharacterEncoding("UTF-8");
        ec.setResponseHeader("Cache-Control", "no-store");
        ec.setResponseHeader("Pragma", "private");
        ec.setResponseHeader("Expires", "1");
    }
}

Related Tutorials