This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds and have James Denton on-line!
See this thread for details.
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

help with session listener  RSS feed

Ranch Hand
Posts: 618
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please excuse the length of this post. I'm getting pretty frustrated, and so I want to give as much info as might be necessary.

I'm trying to add a session listener to the "mainApp" web application of a production website that currently has a little over 2000 concurrent users at peak time, and this site is powered by Tomcat 4 on Windows. However, my session listener doesn't seem to be listening. At the top of my web.xml (before any servlet elements, and I have nothing like a filter or anything else before it), I have this:

<listener> <listener-class>mainApp.utility.OurSessionListener</listener-class>

Then in JBuilder, I've created this listener class:

package mainApp.utility;

import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

import mainApp.beans.*;

public class OurSessionListener implements HttpSessionListener {

public void sessionCreated(HttpSessionEvent se) {
HttpSession session = se.getSession();
UserAcctBean user = (UserAcctBean)
String loginID = user.getLoginID();
System.out.println("Added session: " + session.getId() + " for user
" + user.getLoginID());
SystemControl.addActiveUser(session.getId(), user.getLoginID() );

public void sessionDestroyed(HttpSessionEvent se) {
HttpSession session = se.getSession();
System.out.println("Removed session: " + session.getId());

My SystemControl's static HashMap doesn't seem to be getting updated, and the above methods aren't even getting called because nothing is going to stdout when I log in as different users.

One of the main things I'm not sure about is where this SessionListener class needs to be. Part of the confusion stems from the fact that the original developer set it up so that when JBuilder builds the app it puts all class files in all packages into a single JAR file that we stick into Tomcat\common\lib (whereas all the JSPs go into the Tomcat\webapps\mainApp directory). I've discovered that servlets created in JBuilder do get put into the JAR file, but they're not accessible there and so I have to put them into Tomcat's common\classes directory (and mimic the directory structure implied by whatever package they're in).

I wasn't sure if the same needed to be done with this session listener class, so I also copied its class file to the same place even though it's in the JAR file as well. That doesn't seem to help.

I have the session listener declared in the global web.xml in Tomcat\conf, but then I wondered if it needs to be declared in the application's web.xml located under its WEB-INF directory, and so I declared it in there, and also created the directory webapps\mainApp\WEB-INF\classes\mainApp\utility and copied the class file to there, but this still doesn't seem to help when I restart Tomcat!

When a user logs in, their account info gets loaded and they go to a welcome page that accesses some session beans, so I assume that by that point a session has been created. However, when I check in Tomcat's logs directory, nothing is going to stdout, so it's like sessionCreated isn't being called in my listener class! Any ideas why? Thanks...

Stephen Huey
Ranch Hand
Posts: 618
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In case anyone is searching for the answer to this, check this out:

With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!