Bookmark Topic Watch 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 ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Many ranchers seem confused about which listeners to declare in web.xml.

The main point is :
Classes implementing interfaces other than HttpSessionBindingListener and HttpSessionActivationListener need to be declared in DD.

A trick to remember which listeners to register in the deployment descriptor: Listeners can be classified in 2 categories:

  • Those that are interested in all events of one type (e.g. HttpSessionListener - interested in ALL HTTP session creation and destruction events, HttpSessionAttributeListener - interested in all session attribute events - any attribute added / removed / replaced), and all the listeners for ServletContext and ServletRequest. The container creates one instance of each of these listeners.

  • Those that are interested only in specific events of one type. There are 2 listeners of this type :
    • HttpSessionBindingListener : interested in knowing when it is itself bound / unbound to a HttpSession
    • HttpSessionActivationListener : interested in knowing when only the session it is bound to is activated or passivated, so that it can prepare itself for activation / passivation)

    We create the instances of these listeners and set them as attributes in specific http sessions.

    The first type of listeners are configured in the deployment descriptor - as their methods are ALWAYS called when the event occurs.

    The second type of listeners are not configured in the deployment descriptor.

    Note: The HFSJ book is in error on this matter, as the errata has confirmed.

      Bookmark Topic Watch Topic
    • New Topic