| Author |
Informal Survey - Use of Listeners
|
Bert Bates
author
Sheriff
Joined: Oct 14, 2002
Posts: 8712
|
|
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
|
Eliminate fossil fuel subsidies. (If you're not on the edge, you're taking up too much room.)
|
 |
Chris Mathews
Ranch Hand
Joined: Jul 18, 2001
Posts: 2712
|
|
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
Joined: Jul 18, 2001
Posts: 2712
|
|
|
I've also found HttpSessionListener useful for doing things like tracking which users are currently online.
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56151
|
|
|
What Chris said, and what Chris said, These are the two uses to which I have put listeners.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Kyle Brown
author
Ranch Hand
Joined: Aug 10, 2001
Posts: 3879
|
|
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 ]
|
Kyle Brown, Author of Persistence in the Enterprise and Enterprise Java Programming with IBM Websphere, 2nd Edition
See my homepage at http://www.kyle-brown.com/ for other WebSphere information.
|
 |
Bert Bates
author
Sheriff
Joined: Oct 14, 2002
Posts: 8712
|
|
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?
|
 |
rick zorich
Greenhorn
Joined: Aug 31, 2003
Posts: 16
|
|
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
Joined: Aug 31, 2003
Posts: 16
|
|
|
The first time you request A.jsp, the output is "hello". Refresh it couple times to see different times.
|
 |
Ray Stojonic
Ranch Hand
Joined: Aug 08, 2003
Posts: 326
|
|
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.
|
 |
 |
|
|
subject: Informal Survey - Use of Listeners
|
|
|