//SessionCounterPage1.html
Page 1
Session Counter Demo
Click here to visit second page .
//SessionCount.java
package Session;
import javax.servlet.http.*;
public class SessionCount implements HttpSessionListener{
private static int numberOfSessionsCount = 0;
public void sessionCreated (HttpSessionEvent evt){
numberOfSessionsCount++;
}
public void sessionDestroyed (HttpSessionEvent evt){
numberOfSessionsCount--;
}
// here is our own method to return the number of current sessions
public static int getNumberOfSessionsCount(){
return numberOfSessionsCount;
}
}
//SessionCounterJspPage1.jsp
Page 1
Session Demo Using HttpSessionListener
">Click here to visit page page.
//SessionCounterJspPage2.jsp
Page 2
Session Counter
">Click here to visit first page.
//SessionCounterForJspPage.jsp
Session Counter
Session Counter
There are
<%=Session.SessionCount.getNumberOfSessionsCount()%> active sessions in the server.