Session Scope Bean : Session « JSP « Java Tutorial

package beans;

public class Counter 

    private int counter = 0;

    public void setCounter(int value) 
        this.counter = value;

    public int getCounter() 
        return this.counter;

    public Counter() 

Jsp code

        <TITLE>Using Beans and Session Scope</TITLE>

        <H1>Using Beans and Session Scope</H1>

        <jsp:useBean id="bean1" class="beans.Counter" scope="session" />

        bean1.setCounter(bean1.getCounter() + 1);
        The counter value is: <jsp:getProperty name="bean1" property="counter" /> 
  Download: 2 k)

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