<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>Answers to: How can I set response headers in JSF?</title><link>https://answers.axonivy.com/questions/904/how-can-i-set-response-headers-in-jsf</link><description>&lt;p&gt;How is it possible to set http response headers in JSF? E.g. to set the &lt;code&gt;Cache-Control&lt;/code&gt; reponse header to &lt;code&gt;no-cache, no-store&lt;/code&gt;.&lt;/p&gt;</description><atom:link href="https://answers.axonivy.com/questions/904/how-can-i-set-response-headers-in-jsf" rel="self"></atom:link><language>en</language><lastBuildDate>Fri, 08 Aug 2014 16:46:54 -0400</lastBuildDate><item><title>Answer by Christian Strebel</title><link>https://answers.axonivy.com/questions/904/how-can-i-set-response-headers-in-jsf/905</link><description>&lt;p&gt;&lt;strong&gt;To set it on the HTML/JSF responses you can configure it in your layouts directly with the expression language:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Directly in the layout:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&amp;lt;f:event type="preRenderView" listener="#{facesContext.externalContext.response.setHeader('Cache-Control', 'no-cache, no-store')}" /&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In a Managed Bean, called in the layout:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&amp;lt;f:event type="preRenderView" listener="#{responseHeader.setNoCache}" /&amp;gt;

@javax.faces.bean.ManagedBean
@ApplicationScoped
public class ResponseHeader {
    public void setNoCache() {
        HttpServletResponse response = (HttpServletResponse) FacesContext
                .getCurrentInstance().getExternalContext().getResponse();
        response.setHeader("Cache-Control", "no-cache, no-store");
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;hr&gt;
&lt;p&gt;&lt;strong&gt;Response Header Filter&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;To generally manage response headers also for other resources than the HTML/JSF responses (e.g. images etc.) the best way is to &lt;a href="http://livingtao.blogspot.ch/2012/01/servlet-filter-to-set-response-headers.html"&gt;create a own servlet filter&lt;/a&gt; or use the exisitng one like &lt;a href="http://code.google.com/p/responseheaderfilter/"&gt;ResponseHeaderFilter&lt;/a&gt;.&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;&lt;strong&gt;Onyl expires header for all resources&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;If you only want to control the expires header, there is already a nice built in servlet filter for that.
&lt;a href="https://tomcat.apache.org/tomcat-7.0-doc/api/org/apache/catalina/filters/ExpiresFilter.html"&gt;See tomcat documentation for more info&lt;/a&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;&lt;strong&gt;With Apache&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;If you use the &lt;a href="http://www.xpertivy.ch/releases/Xpert.ivy/latest/documents/ServerGuideHtml/ivy.server.integration.apacheserver.html"&gt;Apache Integration&lt;/a&gt; you can use the &lt;a href="http://httpd.apache.org/docs/current/mod/mod_headers.html"&gt;Module mod headers&lt;/a&gt; or the &lt;a href="http://httpd.apache.org/docs/current/mod/mod_expires.html"&gt;Module mod expires&lt;/a&gt;.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Christian Strebel</dc:creator><pubDate>Fri, 08 Aug 2014 16:46:54 -0400</pubDate><guid>https://answers.axonivy.com/questions/904/how-can-i-set-response-headers-in-jsf/905</guid></item></channel></rss>