This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Rust Web Development and have Bastian Gruber on-line!
See this thread for details.
Win a copy of Rust Web Development this week in the Other Languages forum!
    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 ...
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
  • Al Hobbs
  • Piet Souris
  • Frits Walraven
  • 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.

    You showed up just in time for the waffles! And this tiny ad:
    Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
      Bookmark Topic Watch Topic
    • New Topic