jsf - 如何控制 JSF 中的 http header ?

标签 jsf servlets jsf-2 http-headers omnifaces

PF 3.5(4.0)、Omnifaces 1.6.3、Mojara 2.1.21

是否可以控制将在 JSF xhtml 页面内发送的 http header ?我的意思是:

.xhtml:

<html xmlns:http="a cool name space">

  <h:head>
    <http:headers header="Cache-Control" value="no-cache, no-store, must-revalidate" />
  </h:head>
  <h:body> .... </h:body>
</html>

最佳答案

你的意思是不指示浏览器缓存它?只需使用过滤器并将您想要的内容添加到响应标题中:

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.
}

另请参阅:

关于jsf - 如何控制 JSF 中的 http header ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20263902/

相关文章:

string - :outputText line break for long words within strings

java - 尝试建立一个可在多个地方使用的列表

html - Servlet返回“HTTP状态404请求的资源(/Servlet)不可用”

jsf - java.lang.IllegalStateException:找不到工厂javax.faces.application.ApplicationFactory的备份

jsf - 如何使用 JSF 2.0 复合组件实现动态列表?

java - 用户界面 :repeat does not work in JSF 2. 0?

jsf - 是否有任何 JSF 或 Primefaces 照片标记器组件?

jsf - JPA 实体和/vs DTO

java - 如何实现jsp页面的 session 跟踪

java - request.getCharacterEncoding() 返回 NULL... 为什么?