• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

clarification

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i was taking javaranch mock exam and came across the following question :-
A class that will recieve notification if an Attribute is added to or removed from a session will implement which interface?
What is the correct answer for this.
According to me it shud be HttpSessionBindingListener but it mentioned the correct answer as HttpSessionAttributeListener (i did not choose this because class implementing this interface has to be specified in DD).
Please clarify and help me in clearing my doubt.
 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The correct answer is HttpSessionAttributeListener.
HttpSessionBindingListener is implemented by an object so that the object itself will be notified if it is bound or unbound to a session. That will not work for all objects (for instance, String does not implement this interface, so a String instance can't be notified when it is added to a session).
HttpSessionAttributeListener is implemented by a class when that class wants to be notified that any attribute has been added to the session. That is the other difference: HttpSessionBindingListener can only notify a specific object that it has been added; HttpSessionAttributeListener is notified when any attribute has been added.
So, when you develop a class that is to be notified when any attribute is added to a session, you would implement HttpSessionAttributeListener, and then register that class through the listener element of the deployment descriptor. The listener element takes the fully qualified name of the class, not the listener interface.
[ January 20, 2003: Message edited by: Kevin Mukhar ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic