Axon.ivy 7.0 - the Digital Business Platform - is out now...

How is it possible to set http response headers in JSF? E.g. to set the Cache-Control reponse header to no-cache, no-store.

asked 08.08.2014 at 16:40

SupportIvyTeam's gravatar image

SupportIvyTeam ♦♦
830435873
accept rate: 81%


To set it on the HTML/JSF responses you can configure it in your layouts directly with the expression language:

Directly in the layout:

<f:event type="preRenderView" listener="#{facesContext.externalContext.response.setHeader('Cache-Control', 'no-cache, no-store')}" />

In a Managed Bean, called in the layout:

<f:event type="preRenderView" listener="#{responseHeader.setNoCache}" />

@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");
    }
}

Response Header Filter

To generally manage response headers also for other resources than the HTML/JSF responses (e.g. images etc.) the best way is to create a own servlet filter or use the exisitng one like ResponseHeaderFilter.


Onyl expires header for all resources

If you only want to control the expires header, there is already a nice built in servlet filter for that. See tomcat documentation for more info


With Apache

If you use the Apache Integration you can use the Module mod headers or the Module mod expires.

link

answered 08.08.2014 at 16:46

Christian%20Strebel's gravatar image

Christian St... ♦
2.4k21028
accept rate: 88%

edited 11.08.2014 at 09:34

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×60
×49

Asked: 08.08.2014 at 16:40

Seen: 7,428 times

Last updated: 12.05 at 03:35