Using Bean Counter JSP
//File: BeanCounter.jsp <HTML> <HEAD> </HEAD> <BODY> <%@ page language="java" %> <jsp:useBean id="counter" scope="session" class="beans.Counter" /> <jsp:setProperty name="counter" property="count" param="count" /> <% out.println("Count from scriptlet code : " + counter.getCount() + "<BR>"); %> Count from jsp:getProperty : <jsp:getProperty name="counter" property="count" /><BR> </BODY> </HTML> /////////////////////////////////////////////////////////// //File: Counter.java package beans; import java.io.Serializable; public class Counter implements Serializable{ // Initialize the bean on creation int count = 0; // Parameterless Constructor public Counter() { } // Property Getter public int getCount() { // Increment the count property, with every request count++; return this.count; } // Property Setter public void setCount(int count) { this.count = count; } }