Get Session ID, creation time and last accessed time : Session « JSP « Java Tutorial






<%@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>








23.40.Session
23.40.1.Get Session ID, creation time and last accessed time
23.40.2.Set and get variable to a session
23.40.3.Session Scope Bean
23.40.4.Reference Session Value Across JSP Page