一、清除页面缓存
在jsp页里:
<%
response.setHeader("Pragma","No-cache");
response.setHeader("Cache-Control","no-cache");
response.setDateHeader("Expires", 0);
response.flushBuffer();
%>
在html页里:
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Cache-Control" CONTENT="no-cache">
<META HTTP-EQUIV="Expires" CONTENT="0">
二、清除cookie
<%
Cookie killMyCookie = new Cookie("mycookie", null);
killMyCookie.setMaxAge(0);
killMyCookie.setPath("/");
response.addCookie(killMyCookie);
%>
三、清除session
页面载入时清除session:
<%@ page language="java" %>
<%
session.invalidate();
%>
页面关闭时清除session,需要捕获windows.onclose事件,再调用清除session方法。
本文介绍了如何在Web应用中清除页面缓存、Cookie和Session的方法。对于缓存,可以通过设置响应头来禁止浏览器缓存页面;清除Cookie则需要创建一个同名Cookie并将其有效期设为0;而Session的清除可以通过invalidate方法实现。
1031

被折叠的 条评论
为什么被折叠?



