Hi,
I have a got some doubts in HttpSessionAttributeListener and HttpSessionBindingListener.
1.when you remove an attribute from a Session will that trigger attributeRemoved() and ValueUnbound() methods.
If so why is that not happening in the below code.
I got a
servlet like this
req.getSession().setAttribute("X",new SessionAttribute("Azhar"));
req.getSession().setAttribute("X",new SessionAttribute("Sachin"));
req.getSession().setAttribute("X","senthil");
req.getSession().removeAttribute("X");
and my Binding listener class
class SessionAttribute implements HttpSessionBindingListener
{
SessionAttribute(
String name)
{this.name =name;}
String getName()
{return name;}
String name;
public void valueBound(HttpSessionBindingEvent ev)
{ System.out.println("B=>"+ev.getName()+"|"+((SessionAttribute)ev.getValue()).getName());
}
public void valueUnbound(HttpSessionBindingEvent ev)
{
System.out.println("UB=>"+ev.getName()+"|"+((SessionAttribute)ev.getValue()).getName());
}
}
And the SessionAttributeListener class
public class SessionAttributeListener implements HttpSessionAttributeListener
{
public void attributeAdded(HttpSessionBindingEvent ev)
{
System.out.println("Added=>"+ev.getName()+"|"+((SessionAttribute)ev.getValue()).getName());
}
public void attributeReplaced(HttpSessionBindingEvent ev)
{
System.out.println("Replaced=>"+ev.getName()+"|"+((SessionAttribute)ev.getValue()).getName());
}
public void attributeRemoved(HttpSessionBindingEvent ev)
{
System.out.println("Removed=> "+ev.getName()+"|"+((SessionAttribute)ev.getValue()).getName());
}
}
But the output i'm getting is something awry
B=>X|Azhar
Added=>X|Azhar
B=>X|Sachin
Replaced=>X|Sachin
Replaced=>X|Sachin
why my remove method of HttpSessionAttributeListener and the Unbound method of BindingListener is not getting called.
Please clarify this
