• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

more and more...

 
friso jonge
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
another question which is in line with the discussions on listeners...
which of the following methods is invoked when removeAttribute(String name) is called on a session object.
a) valueRemoved(HSBE event)
b) attirbutRemoved(HSBE event)
c) valueUnbound(HSBE event)
d) attributeUnbound(HSBE event)
book answer:
C - when an attribute is unbound from a session, an HttpSessionBindingEvent is generated and sent to all registered HttpSessionBindingListeners via the valueUnbound(..) method.
my question is how do you register an HttpSessionBindingListener is you implement this listener (as an interface) to your object/class. I had the impression HttpSessionBindingListeners could not be added in the web.xml
another question is, why is (apart from spelling) answer b a wrong answer. I agree the listener for this needs to be in the web.xml, but lets assume it is in the web.xml, then it is a right answer. Or are there other opinions ?
thanks,
friso
 
k space
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HttpSessionBindingListener doesn't need to be registered. As long as your object implements the interface, web container will notify your object through valueBound and valueUnbound methods when it is being added or removed from a session.
With you assumption (i.e. a HttpSessionAttributeListener is specified in web.xml) and apart from spelling, I think b is correct too.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic