我思故我强

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" "http://www.w3.org/TR/html4/loose.dtd">
<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 李云泽 阅读(3260) 评论(1)  编辑  收藏 所属分类: J2EEJava代码

评论

# re: jsp查看session信息[未登录] 2013-04-16 16:31 32

32  回复  更多评论   


只有注册用户登录后才能发表评论。


网站导航: