Source Code : Servlet: session listener
Java Is Open Source Programming Language You Can Download From Java and Java Libraries From http://www.oracle.com.
Click Here to download
We provide this code related to title for you to solve your developing problem easily. Libraries which is import in this program you can download from http://www.oracle.com.
Click Here or search from google with Libraries Name you get jar file related it
Servlet: session listener
import java.util.Date;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
public class SessionListen implements HttpSessionListener {
private int sessionCount;
public SessionListen() {
this.sessionCount = 0;
}
public void sessionCreated(HttpSessionEvent se) {
HttpSession session = se.getSession();
session.setMaxInactiveInterval(60);
synchronized (this) {
sessionCount++;
}
String id = session.getId();
Date now = new Date();
String message = new StringBuffer("New Session created on ").append(
now.toString()).append("
ID: ").append(id).append("
")
.append("There are now ").append("" + sessionCount).append(
" live sessions in the application.").toString();
System.out.println(message);
}
public void sessionDestroyed(HttpSessionEvent se) {
HttpSession session = se.getSession();
String id = session.getId();
synchronized (this) {
--sessionCount;
}
String message = new StringBuffer("Session destroyed"
+ "
Value of destroyed session ID is").append("" + id).append(
"
").append("There are now ").append("" + sessionCount)
.append(" live sessions in the application.").toString();
System.out.println(message);
}
}
Thank with us