如何在JSF中控制HTTP标头? [英] How to control http headers in JSF?
本文介绍了如何在JSF中控制HTTP标头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
PF 3.5(4.0),Omnifaces 1.6.3,Mojara 2.1.21
PF 3.5(4.0), Omnifaces 1.6.3, Mojara 2.1.21
是否可以控制将在JSF xhtml页面内部发送的HTTP标头?我的意思是:
Is it possible to control http headers which will be sent inside of JSF xhtml page ? I mean something like:
.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>
推荐答案
您的意思是不指示浏览器进行缓存吗?只需使用过滤器,然后将所需的内容添加到响应头即可:
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.
}
另请参见:
- HTTP response caching
- How do a web filter in JSF 2?
- How to control web page caching, across all browsers?
这篇关于如何在JSF中控制HTTP标头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文