防止IE缓存 [英] Prevent IE caching

查看:261
本文介绍了防止IE缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Struts开发Java EE Web应用程序。问题出在Internet Explorer缓存上。如果用户注销,他可以访问某些页面,因为它们被缓存并且没有请求。如果我点击刷新它工作正常。此外,如果用户再次进入登录页面,它将不会重定向他,因为该页面也被缓存。

I am developing a Java EE web application using Struts. The problem is with Internet Explorer caching. If an user logs out he can access some pages because they are cached and no request is made. If I hit refresh it works fine. Also if an user goes to login page again it won't redirect him because that page is also cached.

我想到了两个解决方案:

Two solutions come to my mind:


  1. 编写一个拦截器(像servlet过滤器一样)添加到响应头no-cache等。

  2. 或者把< meta> 每页的标签。

  1. Writing an Interceptor (servlet filter like) to add to response header no-cache etc.
  2. Or or put <meta> tags at each page.

我应该做哪一个?

推荐答案

而是在页面的 HttpServletResponse 上设置以下标题(s )有问题,所以你不需要手动在所有页面上进行复制:

Rather set the following headers on the HttpServletResponse of the page(s) in question so that you don't need to copypaste it over all pages manually:

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.

这相当于手动在页面中设置以下元标题:

This is equivalent to setting the following meta headers in the page(s) manually:

<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Expires" content="0">

另见这个答案。在测试之前不要忘记清除浏览器缓存;)

Also see this answer. Don't forget to clear browser cache before testing ;)

这篇关于防止IE缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆