This week's book giveaway is in the Open Source forum.
We're giving away four copies of Programmers Guide to Apache Thrift and have Randy Abernethy on-line!
See this thread for details.
Win a copy of Programmers Guide to Apache Thrift this week in the Open Source 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis
  • Mark post as helpful
  • send pies
  • 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.

    WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
    ScroogeXHTML - small and flexible RTF to HTML converter library
      Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!