JSP技巧篇---防止瀏覽器快取網頁
瀏
覽器為了加速使用者的瀏覽速度,常會將瀏覽過的網頁快取到硬盤,下次瀏覽同一頁時,便去硬盤里面去找,但現在的網頁常是動態的,為了避免使用者抓到硬盤內
過期的數據,JSP可用下面的方式來防止瀏覽器快取住網頁,此方法便可保證使用者到這個網頁時始終都可看到最新的資料。
1.JSP語法
<%
??? ??? response.setHeader( " Pragma " , " no-cache " );
??? ??? response.setHeader( " Cache-Control " , " no-cache " );
??? ??? response.setDateHeader( " Expires " , 0 );
??? %>
??? ??? response.setHeader( " Pragma " , " no-cache " );
??? ??? response.setHeader( " Cache-Control " , " no-cache " );
??? ??? response.setDateHeader( " Expires " , 0 );
??? %>
2.也可以用以下的HTML語法,可用在靜態網頁上
<
meta?http
-
equiv?
=
?
"
Pragma
"
?content
=
"
no-cache
"
>
??? < meta?http - equiv = " Cache-Control " ?content = " no-cache " >
??? < meta?http - equiv? = ? " Expires " ?content = " 0 " >
??? < meta?http - equiv = " Cache-Control " ?content = " no-cache " >
??? < meta?http - equiv? = ? " Expires " ?content = " 0 " >
注意,這些HTML語法要下在<head></head>的標簽內。
posted on 2006-05-05 22:54 paulwong 閱讀(327) 評論(0) 編輯 收藏 所屬分類: J2EE