Using setter to change value and read it back by jsp get property : Get Set Property « JSP « Java Tutorial






Jsp code

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

    <BODY>
        <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" /> 
    </BODY>
</HTML>

Counter.java

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() 
    {
    }
}
  Download:  UsingSetterToChangeValueReadByJspGetProperty.zip( 2 k)








23.42.Get Set Property
23.42.1.Using jsp getProperty to get value from java bean
23.42.2.Using setter to change value and read it back by jsp get property