Set and get variable to a session : Session « JSP « Java Tutorial






<HTML>
    <HEAD>
        <TITLE>Using the Application Object</TITLE>
    </HEAD>

    <BODY>
        <H1>Using the Application Object</H1>
        <%
        Integer counter = (Integer)session.getAttribute("counter");
        String heading = null;
        if (counter == null) {
            counter = new Integer(1);
        } else {
            counter = new Integer(counter.intValue() + 1);
        }

        session.setAttribute("counter", counter);

        Integer i = (Integer)application.getAttribute("i");
        if (i == null) {
            i = new Integer(1);
        } else {
            i = new Integer(i.intValue() + 1);
        }

        application.setAttribute("i", i);
        %>

        You have visited this page <%=counter%> times.
        <BR>
        This page has been visited by all users <%=i%> times.
    </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