I believe you 'may' be looking for something like this which will put all of the valid HttpSession objects into a HashMap and place that object into a HashMap to be retrieved out of the
servlet context?
public class SessionHolder implements HttpSessionListener {
private ServletContext context = null;
private HashMap sessions = new HashMap();
public HashMap getSessionHolder() {
return sessions;
}
public void sessionCreated(HttpSessionEvent event) {
HttpSession session = event.getSession();
sessions.put(session.getId(), session);
if(context == null)
storeInServletContext(event);
}
public void sessionDestroyed(HttpSessionEvent event) {
HttpSession session = event.getSession();
sessions.remove(session.getId());
}
private void storeInServletContext(HttpSessionEvent event) {
HttpSession session = event.getSession();
context = session.getServletContext();
context.setAttribute("sessionHolder", this);
}
}