Short answer
valueBound is not being called because MySessionListener
is not the object being added to a session.
If TestValue
implemented HttpSessionBindingListener
it's valueBound
method would be called.
Longer Explanation
HttpSessionBindingListener
is used to notify the object that it is being added to a session.
HttpSessionAttributeListener
is used (as you discovered) for attributes being added/removed from a session.
With the HttpSessionBindingListener
here is what the container is saying: "Hey TestValue
, you were added to a session"
With the HttpSessionAttributeListener
here is what the container is saying: "Hey MySessionListener, an attribute was added to a session"
So, if TestValue
implements HttpSessionBindingListener
, it would have valueBound called when added to a session:
session.setAttribute("name",new TestValue());
In your case, if you added an instance of MySessionListener
to a session (not that you'd want to, but because it implements HttpSessionBindingListener
) it would call the valueBound
method when added to a session:
session.setAttribute("name", new MySessionListener());
Also see: Practical Usage of HttpSessionBindingListener And HttpSessionAttributeListener