• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HttpSessionBindingListener

 
Shobhan Ganta
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

This question is from one of the mockup tests in webpage

Q: 130 You have a use case in your web application that adds several session-scoped
attributes. At the end of the use case, one of these objects, the manager attribute, is removed and then it
needs to decide which of the other session-scoped attributes to remove.
How can this goal be accomplished?
A. The object of the manager attribute should implement the HttpSessionBindingListener and it should call the
removeAttribute method on the appropriate session attributes.
B. The object of the manager attribute should implement the HttpSessionListener and it should call the
removeAttribute method on the appropriate session attributes.
C. The object of the manager attribute should implement the HttpSessionBindingListener and it should call the
deleteAttribute method on the appropriate session attributes.
D. The object of the manager attribute should implement the HttpSessionListener and it should call the
deleteAttribute method on the appropriate session attributes.


The correct answer given is A.

But HttpSessionBindingListener doesn't have removeAttribute() method, so it should have been HttpSessionAttributeListener which contains the removeAttribute() method.

Thanks
Shobhan
 
Piotr Nowicki
Ranch Hand
Posts: 611
1
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Shobhan!

The HttpSessionBindingListener has a HttpSessionBindingEvent, which in turn has a getSession() method which returns... a session object :-)

Than you can remove the needed attributes using the session object.

The HttpSessionAttributeListener you pointed, in my opinion, could also be used, but it would need to test everytime any variable is removed from the session scope, if it's the manager object and then react.
However, this option is not included in the answers :-)

Cheers!
 
Shobhan Ganta
Ranch Hand
Posts: 37
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Pedro.
The HttpSessionBindingListener has a HttpSessionBindingEvent, which in turn has a getSession() method which returns... a session object :-)

This explains how we can get HttpSession from HttpSessionBindingEvent and call removeAttribute() method.

Thanks
Shobhan
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic