如何禁止浏览器缓存,网上搜到的解决方法都测试无效。

基本上全都是

Cache-Control: no-cache
Pragma: no-cache
Expires: 0

Google了一下,找到了解决方法。

设置response header 的效果就是 返回的时候一定是重新请求页面的。

Using PHP:

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

Using Java Servlet, or Node.js:

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

Using ASP.NET:

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

Using ASP:

Response.addHeader "Cache-Control","no-cache, no-store, must-revalidate"' HTTP 1.1.
Response.addHeader "Pragma","no-cache"' HTTP 1.0.
Response.addHeader "Expires","0"' Proxies.

Using Ruby on Rails, or Python on Flask:

response.headers["Cache-Control"]="no-cache, no-store, must-revalidate"# HTTP 1.1.
response.headers["Pragma"]="no-cache"# HTTP 1.0.
response.headers["Expires"]="0"# Proxies.

Using Google Go:

responseWriter.Header().Set("Cache-Control","no-cache, no-store, must-revalidate")// HTTP 1.1.
responseWriter.Header().Set("Pragma","no-cache")// HTTP 1.0.
responseWriter.Header().Set("Expires","0")// Proxies.

Using Apache .htaccess file:

<IfModulemod_headers.c>
Header set Cache-Control "no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
Header set Expires 0
</IfModule>

Using HTML4:

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

HTML meta tags vs HTTP response headers

根据SO上面的说法,

如果通过HTTP访问,HTTP response headers 是优先于 meta tags 的。但

是,第一次打开是通过HTTP访问的,而返回的时候是从本地读取的。

 
我在自己尝试的时候,发现这两个都需要设置 才能清除页面表单记录。Google浏览器 和 IE11测试通过,页面的记录消除。其他的浏览器未测试。(推测是因为上面的原因)
如果多次测试发现 页面表单的记录还在。
 
但是可以保证,只要写了HTTP response headers 返回的时候一定会重新请求。
 
部分代码如下
<%@ page language="java" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%
response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1.
response.setHeader("Pragma", "no-cache"); // HTTP 1.0.
response.setHeader("Expires", "0"); // Proxies.
%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>index.jsp</title> <meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache, no-store, must-revalidate" >
<meta http-equiv="expires" content="0" >

传送门:StackOverFlow

 

应用

在防止表单重复提交的时候非常有用。

禁止浏览器缓存- make sure web page is not cached的更多相关文章

  1. Servlet过滤器——使用过滤器禁止浏览器缓存页面

    1.概述 IE缓存虽然能提高已储存网站的访问速度,但是过度的IE缓存会影响浏览器的响应速度.同时还可能为网站的运行带来一些不必要的麻烦.例如:可能会因为浏览器缓存的应用,而导致Web服务器不能准确的计 ...

  2. filter 过滤器 禁止浏览器缓存

    public class BrowserNoCacheFilter implements Filter { public void init(FilterConfig filterconfig) th ...

  3. 禁止浏览器缓存input值

    如果不想让浏览器缓存input的值,有2种方法: 方法一: 在不想使用缓存的input中添加 autocomplete="off"; <input type="te ...

  4. 谷歌浏览器(Chrome)禁止浏览器缓存 设置

    在开发项目期间用谷歌浏览器调试,他总是缓存我的css样式这个很气人啊,后经过摸索找到了方法,如下 先F12或者shift+ctrl+j 打开调试者工具,在找Network这个tab按钮,点击进入,勾选 ...

  5. nginx 禁止浏览器缓存

    如果我们使用Nginx作为静态资源服务器,那么可以使用expires进行缓存控制. location /{ expires 1s; } 如果Get页面未做任何修改,服务器就是对客户端返回304 Not ...

  6. 禁止浏览器缓存js

    方法:在js文件后加上数学随机数; Math.random() 比如:源代码为 <script src="./js/lib/require/require.js" data- ...

  7. ajax禁止浏览器缓存

    把cache 设置为false ,把 ifModified 设置为true //工作计划function workprogram(date_time){    $.ajax({        asyn ...

  8. [原创]java WEB学习笔记45:自定义HttpFilter类,理解多个Filter 代码的执行顺序,Filterdemo:禁用浏览器缓存的Filter,字符编码的Filter,检查用户是否登陆过的Filter

    本博客为原创:综合 尚硅谷(http://www.atguigu.com)的系统教程(深表感谢)和 网络上的现有资源(博客,文档,图书等),资源的出处我会标明 本博客的目的:①总结自己的学习过程,相当 ...

  9. 禁止火狐浏览器缓存input标签方法

    禁止火狐浏览器缓存input标签方法 问题1:在火狐浏览器里,云平台的输入框.选项框.勾选框…填写之后按F5刷新页面,之前填的东西会保留着,其它浏览器不会火狐强制刷新用Ctrl + F5 浏览器自动保 ...

随机推荐

  1. jmeter基础使用

    1.ServerAgent是服务端的插件2.下载成功后,复制JmeterPlugins-Extras.jar和JmeterPlugins-Standard.jar两个文件,放到jmeter安装文件中的 ...

  2. com.rabbitmq.client.impl.ForgivingExceptionHandler.log:119 -An unexpected connection driver error occured

    在服务器上安装了一个RabbitMq,并新创建了一个用户授予了管理员角色,登录控制台查看一切正常,兴高采烈启动项目进行连接,结果一盆冷水下来,报如下错误: o.s.a.r.l.SimpleMessag ...

  3. Spring 梳理 - 开启并配置 Spring MVC 的方法

    传统web.xm中配置两个上下文+两个context对应的xml+两个上下文bean分别手动配置 传统web.xm中配置两个上下文+两个context对应的xml+<mvc:annotation ...

  4. 【SQL server初级】数据库性能优化三:程序操作优化

    数据库优化包含以下三部分,数据库自身的优化,数据库表优化,程序操作优化.此文为第三部分 数据库性能优化三:程序操作优化 概述:程序访问优化也可以认为是访问SQL语句的优化,一个好的SQL语句是可以减少 ...

  5. netty源码解解析(4.0)-23 ByteBuf内存管理:分配和释放

    ByteBuf内存分配和释放由具体实现负责,抽象类型只定义的内存分配和释放的时机. 内存分配分两个阶段: 第一阶段,初始化时分配内存.第二阶段: 内存不够用时分配新的内存.ByteBuf抽象层没有定义 ...

  6. [LeetCode] 822. Card Flipping Game

    Description On a table are N cards, with a positive integer printed on the front and back of each ca ...

  7. Java 学习笔记之 Stop停止线程

    Stop停止线程: 使用stop()方法停止线程是非常暴力的,会抛出java.lang.ThreadDeath Error,但是我们无需显示捕捉, 以下捕捉只是为了看得更清晰. public clas ...

  8. Android资源管理利器Resources和AssetManager

    前言  : Android工程在运行的时候往往需要引用资源.使用 Resources 来获取 res 目录下的各种与设备相关的资源.而使用 AssetManager 来获取 assets 目录下的资源 ...

  9. android设置透明状态栏

    先是半透明效果(两种方法): 第一种(简单): //直接将下面的代码放在activity中的setContentView(R.layout.activity_main);中之前就行了 if (Buil ...

  10. asp.net core 腾讯验证码的接入

    asp.net core 腾讯验证码的接入 Intro 之前使用的验证码服务是用的极验验证,而且是比较旧的,好久之前接入的,而且验证码服务依赖 Session,有点不太灵活,后来发现腾讯也有验证码服务 ...