How to control http headers in JSF?

前端 未结 2 830
既然无缘
既然无缘 2021-01-22 08:47

PF 3.5(4.0), Omnifaces 1.6.3, Mojara 2.1.21

Is it possible to control http headers which will be sent inside of JSF xhtml page ? I mean something like:

2条回答
  •  走了就别回头了
    2021-01-22 09:39

    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:

    • HTTP response caching
    • How do a web filter in JSF 2?
    • How to control web page caching, across all browsers?

提交回复
热议问题