会话跟踪技术

20 篇文章 0 订阅
17 篇文章 0 订阅
<%@ page import="java.util.Date" %><%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2022/11/23 0023
  Time: 8:22
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
  <head>
    <title>$Title$</title>
  </head>
  <body>
        <%
        //获取绘画信息
        //获取创建时间  当运行jsp时,就自动帮我们创建了一个session对象
          Date createTime = new Date(session.getCreationTime());
          //getLastAccessedTime()最近一次访问的时间
          Date lastAccessTime = new Date(session.getLastAccessedTime());
          //用户ID
          String userID = new String("abcdefg");

          String userIDKey = new String("userIDKey");
          //访问次数
          Integer visitCount = new Integer(0);
          String visitCountKey = "visitCount";
          //判断当前会话是否是一个新的对话,如果是一个新的会话,将数据保存在session里
          if (session.isNew()){
            session.setAttribute(userIDKey,userID);
            session.setAttribute(visitCountKey,visitCount);
          }

          //获取session里的userID和访问次数
          userID =(String) session.getAttribute(userIDKey);
          visitCount = (Integer) session.getAttribute(visitCountKey);
          //每一次访问都会加一
          visitCount +=1;
          //保存加一后 的访问数
          session.setAttribute(visitCountKey,visitCount);
        %>


          <div style="margin: auto;width: 88%;">
            <center>
              <h2>会话跟踪实例</h2>
            </center>
            <table border="1" align="center">
              <tr bgcolor="#949494">
                <th>id</th>
                <th><%=session.getId()%></th>
              </tr>

              <tr>
                <th>创建时间</th>
                <th><%=createTime%></th>
              </tr>

              <tr>
                <th>最近一次访问时间</th>
                <th><%=lastAccessTime%></th>
              </tr>

              <tr>
                <th>用户ID</th>
                <th><%=userID%></th>
              </tr>

              <tr>
                <th>访问次数</th>
                <th><%=visitCount%></th>
              </tr>
            </table>
          </div>
  </body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值