Using Sessions to Track Users : Session « JSP « Java






Using Sessions to Track Users

<%@page import = "java.util.*" session="true"%>
<HTML> 
    <HEAD>
        <TITLE>Using Sessions to Track Users</TITLE>
    </HEAD> 

    <BODY>
        <% 
        Integer counter =  (Integer)session.getAttribute("counter");
        if (counter == null) {
            counter = new Integer(1);
        } else {
            counter = new Integer(counter.intValue() + 1);
        }

        session.setAttribute("counter", counter);
        %>
        <H1>Using Sessions to Track Users</H1>
        Session ID: <%=session.getId()%>
        <BR>
        Session creation time: <%=new Date(session.getCreationTime())%>
        <BR>
        Last accessed time: <%=new Date(session.getLastAccessedTime())%>
        <BR>
        Number of times you've been here: <%=counter%> 
    </BODY> 
</HTML>


           
       








Related examples in the same category

1.JSP: display a session info
2.JSP Session Parameter Rewrite
3.JSP New Session Parameter
4.Jsp Session Cart
5.Use Session Jsp
6.Jsp Using Bean Scope Session
7.Print the request headers and the session attributes
8.Sessions disabled
9.Duplicated session varaibles
10.JSP: view session
11.JSP and session
12.JSP and session 2
13.JSP session counter