gpt4 book ai didi

java - 退出后避免返回页面渲染

转载 作者:行者123 更新时间:2023-11-29 05:59:43 26 4
gpt4 key购买 nike

我见过:

How to control web page caching, across all browsers? enter link description here

我在 JSF 1.2 页面中使用过:

<meta http-equiv="Cache-control" content="no-store, no-cache, must-revalidate"/>
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="-1"/>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8"/>

它在 IE8 和 Chrome 中不起作用!当我使用后退按钮时,它再次显示该页面!怎么了?问候。

最佳答案

这里引用自 How to control web page caching, across all browsers?您在问题中链接但显然被忽略了:

Note that when the page is served over HTTP and a header is present in both the HTTP response headers and the HTML meta tags, then the one specified in the response header will get precedence over the HTML meta tag. The HTML meta tag will only be used when the page is viewed from local disk file system. See also W3 HTML spec chapter 5.2.2. Take care with this when you don't specify them programmatically, because the webserver can namely include some default values. To verify the one and other, you can see/debug them using Firebug Net panel.

显然是这样的。您需要在真正的 HTTP 响应中设置这些 header ,而不是在其 HTML 输出中。对于 JSF 1.x Web 应用程序,最好的方法是创建一个 servlet filter执行任务。这是一个启动示例:

public class NoCacheFilter implements Filter {

@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
HttpServletResponse response = (HttpServletResponse) res;
response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1.
response.setHeader("Pragma", "no-cache"); // HTTP 1.0.
response.setDateHeader("Expires", 0); // Proxies.
chain.doFilter(req, res);
}

// ...
}

将其映射到 web.xml 中感兴趣的 URL 模式,例如*.jsfFacesServlet 的 servlet 名称。

关于java - 退出后避免返回页面渲染,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10657846/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com