国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JSP > 正文

按IE后退按鈕時讓JSP不讀緩存

2024-09-05 00:19:20
字體:
來源:轉載
供稿:網友

在asp里我曾告訴過朋友如何讓asp程序不從緩存里讀取數據,同樣在jsp里也能實現,請看下面:

方法一:

1,使用java提供的方法,在jsp或者servlet中都可以

<%

response.setheader("pragma","no-cache");

response.setheader("cache-control","no-cache");

response.setdateheader("expires",0);

%>

2,使用html標記,如下面:

<head>

<metahttp-equiv="pragma"content="no-cache">

<metahttp-equiv="cache-control"content="no-cache">

<metahttp-equiv="expires"content="0">

</head>

附加說明:

http頭信息“expires”和“cache-control”為應用程序服務器提供了一個控制瀏覽器和代理服務器上緩存的機制。http頭信息expires告訴代理服務器它的緩存頁面何時將過期。http1.1規范中新定義的頭信息cache-control可以通知瀏覽器不緩存任何頁面。當點擊后退按鈕時,瀏覽器重新訪問服務器已獲取頁面。如下是使用cache-control的基本方法:

  1) no-cache:強制緩存從服務器上獲取新的頁面

  2) no-store: 在任何環境下緩存不保存任何頁面

  http1.0規范中的pragma:no-cache等同于http1.1規范中的cache-control:no-cache,同樣可以包含在頭信息中。

  通過使用http頭信息的cache控制,第二個示例應用logoutsamplejsp2解決了logoutsamplejsp1的問題。logoutsamplejsp2與logoutsamplejsp1不同表現在如下代碼段中,這一代碼段加入進所有受保護的頁面中:

//...
response.setheader("cache-control","no-cache"); //forces caches to obtain a new copy of the page from the origin server
response.setheader("cache-control","no-store"); //directs caches not to store the page under any circumstance
response.setdateheader("expires", 0); //causes the proxy cache to see the page as "stale"
response.setheader("pragma","no-cache"); //http 1.0 backward compatibility
string username = (string) session.getattribute("user");
if (null == username) {
 request.setattribute("error", "session has ended. please login.");
 requestdispatcher rd = request.getrequestdispatcher("login.jsp");
 rd.forward(request, response);
}
//...

方法二:

   在ie中也可通過設置實現:把/工具/internet選項/常規/設置/的檢察所存頁面的較新版本,設為每次訪問該頁時都檢查.



收集最實用的網頁特效代碼!

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 遂平县| 乐清市| 长兴县| 大埔区| 阳信县| 德格县| 凌云县| 吉林省| 鄯善县| 诸城市| 宁陕县| 慈溪市| 东阳市| 扶绥县| 大竹县| 盐津县| 洪湖市| 米易县| 宜宾市| 沂南县| 屏南县| 伊春市| 昌平区| 琼中| 额敏县| 清水县| 兴文县| 长丰县| 馆陶县| 迭部县| 铜陵市| 伊川县| 博客| 河南省| 张家界市| 镇巴县| 六盘水市| 出国| 湖南省| 盐城市| 科技|