jsp查看session信息
<%@ page language="java" contentType="text/html; charset=GBK"
?import="java.util.*" pageEncoding="GBK"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<title>Insert title here</title>
</head>
<body>
<%
out.print("<br>"+"session is new:"+session.isNew());
Date created = new Date(session.getCreationTime());
//得到session對象創建的時間
Date accessed = new Date(session.getLastAccessedTime());
//得到最后訪問該session對象的時間
out.println("<br>"+"ID " + session.getId()+" ");
//得到該session的id,并打印
out.println("<br>"+"Created: " + created+" ");
//打印session創建時間
out.println("<br>"+"Last Accessed: " + accessed+" ");
//打印最后訪問時間
session.setAttribute("Name","Tom");
//在session中添加變量Name=Tom
session.setAttribute("UID","12345678");
//在session中添加變量UID=12345678
Enumeration e = session.getAttributeNames();
//得到session中變量名的枚舉對象
while (e.hasMoreElements()) { //遍歷每一個變量
String name = (String)e.nextElement(); //首先得到名字
String value = session.getAttribute(name).toString();
//由名字從session中得到值
out.println("<br>"+name + " = " + value+" "); //打印
}
%>
</body>
</html>
posted on 2007-12-05 10:29 李云澤 閱讀(3283) 評論(1) 編輯 收藏 所屬分類: J2EE 、Java代碼