<%@ page language="java" contentType="text/html;charset=GBK"
import="java.util.*"pageEncoding="GBK"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=GBK">
<title>Insert titlehere</title>
</head>
<body>
<%
out.print("<br>"+"session isnew:"+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>