How to control http headers in JSF?

北慕城南 提交于 2019-12-02 00:44:56
Xtreme Biker

You mean not to instruct the browser for caching it? Just use a filter and add what you want to your response header:

HttpServletResponse res = (HttpServletResponse) response;
if (!req.getRequestURI().startsWith(
        req.getContextPath() + ResourceHandler.RESOURCE_IDENTIFIER)) { // Skip JSF resources //
                                                                        // (CSS/JS/Images/etc)
    res.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1.
    res.setHeader("Pragma", "no-cache"); // HTTP 1.0.
    res.setDateHeader("Expires", 0); // Proxies.
}

See also:

I found a simple solution by adding the line below to your XHTML page:

  <f:event type="preRenderView"
    listener="#{facesContext.externalContext.response.setHeader('Cache-Control', 'no-cache, no-store')}" />
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!