Source Code : Servlet: Session bind 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 bind listener
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionBindingEvent;
import javax.servlet.http.HttpSessionBindingListener;
public class SessionBindListen implements HttpSessionBindingListener {
private Map info;
/** Creates new SessionBindListen */
public SessionBindListen() {
//zero-arg constructor
info = new HashMap();
}
public void valueBound(HttpSessionBindingEvent be) {
HttpSession session = be.getSession();
String id = session.getId();
String name = be.getName();
Object value = be.getValue();
String source = be.getSource().getClass().getName();
String message = new StringBuffer("Attribute bound to session in ")
.append(source).append("
The attribute name: ").append(name)
.append("
").append("The attribute value: ").append(value)
.append("
").append("The session id: ").append(id).toString();
System.out.println(message);
}
public void valueUnbound(HttpSessionBindingEvent be) {
HttpSession session = be.getSession();
String id = session.getId();
String name = be.getName();
if (name == null)
name = "Unknown";
String source = be.getSource().getClass().getName();
String message = new StringBuffer("Attribute unbound from session in ")
.append(source).append("
The attribute name: ").append(name)
.append("
").append("The session id: ").append(id).toString();
//clear Map; send message
info.clear();
System.out.println(message + "
The size of the HashMap is: "
+ info.size());
}
public void addInfo(String name, String email) {
info.put(email, name);
}
}
Thank with us