session.removeAttribute("username"); //註銷session中的username對象
session.removeAttribute("id"); //註銷session中的id對象
session.invalidate(); //關閉session
[代碼] 1、清除頁面緩存 在jsp頁裏
03 |
response.setHeader("Pragma","No-cache"); |
04 |
response.setHeader("Cache-Control","no-cache"); |
05 |
response.setDateHeader("Expires", 0); |
06 |
response.flushBuffer(); |
09 |
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"> |
10 |
<META HTTP-EQUIV="Pragma" CONTENT="no-cache"> |
11 |
<META HTTP-EQUIV="Cache-Control" CONTENT="no-cache"> |
12 |
<META HTTP-EQUIV="Expires" CONTENT="0"> |
[代碼] 2、清除cookie
2 |
Cookie killMyCookie = new Cookie("mycookie", null); |
3 |
killMyCookie.setMaxAge(0); |
4 |
killMyCookie.setPath("/"); |
5 |
response.addCookie(killMyCookie); |
[代碼] 3、清除session
1 |
<%@ page language="java" session="false" %> |
5 |
//在頁面關閉時清除session,須要捕獲windows.onclose事件,再調用清除session方法 |