<%@ 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>
会话跟踪技术
最新推荐文章于 2024-04-28 17:05:59 发布