How to control cache in JSP page?
博客专区 > cyper 的博客 > 博客详情
How to control cache in JSP page?
cyper 发表于3年前
How to control cache in JSP page?
  • 发表于 3年前
  • 阅读 10
  • 收藏 0
  • 点赞 0
  • 评论 0

To start, the complete set is:

httpResponse.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1. httpResponse.setHeader("Pragma", "no-cache"); // HTTP 1.0. httpResponse.setDateHeader("Expires", 0); // Proxies. 

The no-store and must-revalidate are required to get it to work in under each Firefox.

But, even after implementing the above filter, some pages are cached (accessible using browser's back button).

How did you test it? Those headers will actually prevent the browser from requesting the page from the browser cache instead of directly from the server. Best test is to have a Filter to listen on /* and add a debug statement in favor of:

HttpServletRequest httpRequest = (HttpServletRequest) request; String method = httpRequest.getMethod(); String URI = httpRequest.getRequestURI();   System.out.println(method + " request invoked on " + URI);

This should print the actual requests.

Also ensure that you don't override the headers in the JSP page itself using the HTML<meta>tags.

And other pages that are not cached, show Web Page Expired error in Internet Explorer.

You can only get this if the non-cached request was POST request, not a GET request. The GET requests will simply be requested from server again instead of from the browser cache.

共有 人打赏支持
cyper
粉丝 56
博文 619
码字总数 143000
×
cyper
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
* 金额(元)
¥1 ¥5 ¥10 ¥20 其他金额
打赏人
留言
* 支付类型
微信扫码支付
打赏金额:
已支付成功
打赏金额: