FileDocCategorySizeDatePackage
SessionBindListen.javaAPI DocExample1787Fri Jan 24 15:37:40 GMT 2003com.jspservletcookbook

SessionBindListen

public class SessionBindListen extends Object implements HttpSessionBindingListener

Fields Summary
private Map
info
Constructors Summary
public SessionBindListen()
Creates new SessionBindListen

        
        //zero-arg constructor
        info = new HashMap();
    
Methods Summary
public voidaddInfo(java.lang.String name, java.lang.String email)

        
        info.put(email,name);
        
    
public voidvalueBound(javax.servlet.http.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("\nThe attribute name: ").
        append(name).append("\n").append("The attribute value: ").append(value).append("\n").append("The session id: ").append(id).toString();
        
        System.out.println(message);
    
public voidvalueUnbound(javax.servlet.http.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("\nThe attribute name: ").
        append(name).append("\n").append("The session id: ").append(id).toString();
        //clear Map; send message
        info.clear();
        System.out.println(message + "\nThe size of the HashMap is: " + info.size());