我思故我強

          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 李云澤 閱讀(3292) 評論(1)  編輯  收藏 所屬分類: J2EE 、Java代碼

          評論

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

          32  回復  更多評論   

          主站蜘蛛池模板: 福贡县| 佛山市| 哈尔滨市| 茶陵县| 阜宁县| 加查县| 郯城县| 通化县| 淮滨县| 塘沽区| 柏乡县| 方山县| 武城县| 固始县| 孝昌县| 淮安市| 宜春市| 郎溪县| 文安县| 曲阜市| 石台县| 城步| 黄陵县| 汉源县| 汝州市| 赣州市| 海淀区| 聂荣县| 海伦市| 子长县| 鄂伦春自治旗| 临桂县| 肥乡县| 新建县| 高要市| 石泉县| 宜兰县| 舒城县| 新泰市| 诏安县| 滨海县|