• 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

Informal Survey - Use of Listeners

 
author
Posts: 9050
21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Servlet / JSP campers!
We'd like to compile a list of real-world examples of using the various (what are there, about 812?), listener interfaces and classes in the javax.servlet and javax.servlet.http packages. So, for instance, who's ever used HttpSessionAttributeListener, and why did you use it? How about the other 'attribute' listeners? Tell us your stories! (You might get 15 minutes of fame in the upcoming Head First Servlets book!)
Thanks,
Bert
 
Ranch Hand
Posts: 2713
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I increasingly use ServletContextListeners to load configuration information at server startup. It sure beats the ole Servlet with a load-on-startup=1 trick or at least it feels like less of a hack to me.
 
Chris Mathews
Ranch Hand
Posts: 2713
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've also found HttpSessionListener useful for doing things like tracking which users are currently online.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What Chris said, and what Chris said, These are the two uses to which I have put listeners.
 
author
Posts: 3892
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In one financial planning application we used the HttpSessionListener (specifically on valueUndound when the session died) to record information that a user had entered on a long-running process into a relational database keyed by their userid. Then even though the session died, and they were forced to log back in to the application as a result, we could fetch back their application state and redirect them to the right page to let them continue where they left off.
Kyle
[ April 09, 2004: Message edited by: Kyle Brown ]
 
Bert Bates
author
Posts: 9050
21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Cool start! I guess I'd agree that HttpSession and ServletContext are probably the most frequently used...
Has anyone ever used SessionBinding in real life?
How about any of the XxxxxAttribute listeners?
Does anybody use SessionActivation? Do you worry about your sessions getting passivated?
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try this listener. But, please be careful, you will throw a java.lang.StackOverflowError if you let the count go too high. Maybe someone will post code to catch it gracefully.

For testing you could use the following two JSPs.
A.jsp

and B.jsp
 
rick zorich
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The first time you request A.jsp, the output is "hello". Refresh it couple times to see different times.
 
Ranch Hand
Posts: 326
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I used an HttpSessionBindingListener to maintain a context level record locking device.
The basics:
user1 opens record1 to edit some information, listener is added to their session and entry made in lock minder.
user2 attempts to open record1 to edit some information, lock minder reports record1 is already open for editing, so user2 receives the option to be notified when the record1 becomes available, record opens in read-only mode.
user1 logs out/closes record/times out, listener removes entry from lock minder and unlocks record in database (forgot to mention that above...), user2 receives an email letting them know they may now edit the record.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic