On Mon, 6 Aug 2001, Andrew Arrow wrote:

> I added this to my web.xml file:
> 
> <listener>
> <listener-class>
> com.mystuff.SessionListener
> </listener-class>
> </listener>
> 
> I put a HashTable in the class and add each session to the table every time
> sessionCreated is called.  I'd like to be able to access the same instance
> of com.mystuff.SessionListener that Tomcat is using from a jsp page.  (i.e.
> I
> want the JSP page to display a list of all the sessions in the hashtable.)
> 
> If I say:
> 
> <jsp:useBean id="test" scope="application"
> class="com.mystuff.SessionListener" />
> 
> I'll get a new instance of the class right?  I want the SAME instance.
> Anyway to do this?
> 
> 

This question is more appropriate on TOMCAT-USER, but ...

All your JSP pages will get a reference to the same application-scope
instance, but it will be different from the instance created by the
servlet container.  Nobody but the container has a reference to that
instance.

The best approach to a problem like this is to store the Hashtable itself
as an application-scope bean (same as a servlet context attribute from the
perspective of the listener).  That way, your JSP pages have access to the
collection containing all the sessions, without worrying about the object
that is actually maintaining the collection.

Craig


Reply via email to