session.removeAttribute("username"); //注销session中的username对象
session.removeAttribute("id"); //注销session中的id对象
session.invalidate(); //关闭session
[代码] 一、清除页面缓存 在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"> |
[代码] 二、清除cookie
| 2 | Cookie
killMyCookie = new Cookie("mycookie", null); |
| 3 | killMyCookie.setMaxAge(0); |
| 4 | killMyCookie.setPath("/"); |
| 5 | response.addCookie(killMyCookie); |
[代码] 三、清除session
| 1 | <%@
page language="java" session="false" %> |
| 5 | //在页面关闭时清除session,需要捕获windows.onclose事件,再调用清除session方法 |