Hey Phillip,
works great

thanks alot for your help


Terrence


From: Phillip Morelock <[EMAIL PROTECTED]>
Reply-To: "Tomcat Users List" <[EMAIL PROTECTED]>
To: Tomcat Users List <[EMAIL PROTECTED]>
Subject: Re: Listing all currently logged users
Date: Tue, 28 May 2002 11:15:40 -0700
MIME-Version: 1.0
Received: from nagoya.betaversion.org ([192.18.49.131]) by hotmail.com with 
Microsoft SMTPSVC(5.0.2195.4905); Tue, 28 May 2002 11:22:09 -0700
Received: (qmail 3986 invoked by uid 97); 28 May 2002 18:15:39 -0000
Received: (qmail 3974 invoked by uid 98); 28 May 2002 18:15:39 -0000
Mailing-List: contact [EMAIL PROTECTED]; run by ezmlm
Precedence: bulk
List-Unsubscribe: <mailto:[EMAIL PROTECTED]>
List-Subscribe: <mailto:[EMAIL PROTECTED]>
List-Help: <mailto:[EMAIL PROTECTED]>
List-Post: <mailto:[EMAIL PROTECTED]>
List-Id: "Tomcat Users List" <tomcat-user.jakarta.apache.org>
Delivered-To: mailing list [EMAIL PROTECTED]
X-Antivirus: nagoya (v4198 created Apr 24 2002)
User-Agent: Microsoft-Entourage/10.0.0.1309
Message-ID: <[EMAIL PROTECTED]>
In-Reply-To: <[EMAIL PROTECTED]>
X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N
Return-Path: [EMAIL PROTECTED]
X-OriginalArrivalTime: 28 May 2002 18:22:10.0872 (UTC) 
FILETIME=[95300380:01C20674]

The answers are in the documentation, but I will freely admit that the first
time I did this I found it confusing.  So I will give you a couple of
pointers to get you started.

Here's what I would do:

Create a class (JavaBean-style) that holds all the information you want to
hold for each user in the session context (like their String name, maybe IP
address, perhaps a unique ID or database key, etc.).  Make this class
implement HttpSessionBindingListener.

When someone logs in, you create a new instance of this bean, and "bind" it
to their session:
MyBean bean = new MyBean( );
bean.setStuff( stuff );
bean.setSomeOtherStuff( otherStuff );

request.getSession( ).setAttribute( "UserBean", bean ); //THIS is the key

At this point, the instance ("bean") will have its "valueBound( )" method
called (which you have implemented from "HttpSessionBindingListener").
Inside this method, have this object register itself with your big hashtable
or list (which should be a singleton -- google for "java design patterns
singleton" if you don't know what that is).

When the session expires / becomes invalid, the "valueUnbound" method on
your bean will be called (as the bean is unbound from the session which no
longer exists).  You can have THIS method UNregister your object from the
pool.  The object will die and be garbage collected because there wiill no
longer be any reference to it.

cheers
fillup

On 5/28/02 10:55 AM, "Terrence Szeto" <[EMAIL PROTECTED]> wrote:

 > I think I know what you're trying to say.
 >
 > but where does HttpSessionListern go?
 > do I just make it a private variable in a JSP page? Or make a class to
 > implement it.
 >
 > then, what actually fires the HttpSessionBindingEvent to it?
 > and how does the HttpSessionBinding Event know when a user has timed out 
to
 > fire an event to tell the 'master list' that that specific user is gone.
 > any code is help...
 >
 > THanks
 > Terrence
 >
 >
 >
 > From: Phillip Morelock <[EMAIL PROTECTED]>
 > Reply-To: "Tomcat Users List" <[EMAIL PROTECTED]>
 > To: Tomcat Users List <[EMAIL PROTECTED]>
 > Subject: Re: Listing all currently logged users
 > Date: Tue, 28 May 2002 09:48:55 -0700
 > MIME-Version: 1.0
 > Received: from [192.18.49.131] by hotmail.com (3.2) with ESMTP id
 > MHotMailBEBD000D006C40043216C0123183BE510; Tue, 28 May 2002 09:49:17 
-0700
 > Received: (qmail 2522 invoked by uid 97); 28 May 2002 16:48:58 -0000
 > Received: (qmail 2502 invoked by uid 98); 28 May 2002 16:48:57 -0000
 >> From tomcat-user-return-20771-t3szeto Tue, 28 May 2002 09:49:29 -0700
 > Mailing-List: contact [EMAIL PROTECTED]; run by ezmlm
 > Precedence: bulk
 > List-Unsubscribe: <mailto:[EMAIL PROTECTED]>
 > List-Subscribe: <mailto:[EMAIL PROTECTED]>
 > List-Help: <mailto:[EMAIL PROTECTED]>
 > List-Post: <mailto:[EMAIL PROTECTED]>
 > List-Id: "Tomcat Users List" <tomcat-user.jakarta.apache.org>
 > Delivered-To: mailing list [EMAIL PROTECTED]
 > X-Antivirus: nagoya (v4198 created Apr 24 2002)
 > User-Agent: Microsoft-Entourage/10.0.0.1309
 > Message-ID: <[EMAIL PROTECTED]>
 > In-Reply-To: <[EMAIL PROTECTED]>
 > X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N
 >
 > You should really use the lifecycle listener approach and roll your own
 > hashtable- or list-based implementation, depending on your needs.  Going 
for
 > the internals is cool, but it is a non-portable hack.
 >
 > HttpSessionListener is the way to go, IMHO.
 >
 > fillup
 >
 >
 > On 5/27/02 3:13 PM, "Mats Nyberg" <[EMAIL PROTECTED]> wrote:
 >
 >> not beeing the expert I'd take any suitable Realm-interceptor (e.g.*
 >> org.apache.tomcat.request.SimpleRealm*,
 >> or whatever you use depending on your source of userdata).
 >>
 >> I'd subclass it only to maintain a list of people logging in. should be
 >> done in a jiffy, eh ;)
 >>
 >> ~mats
 >>
 >>
 >> Ben Walding wrote:
 >>
 >>> I'm not sure if this is the best way, but I added a
 >>> HttpSessionListener to find out when
 >>> sessions were created / destroyed and just maintained a list.
 >>>
 >>> It is probably more portable than hacking your way into Catalina
 >>> internals.
 >>>
 >>> See the servlet spec for details on lifecycle listeners.
 >>>
 >>> Terrence Szeto wrote:
 >>>
 >>>>
 >>>> Is it possible to list all the users who are currently logged in?
 >>>>
 >>>> I'm using FORM authentication with a JDBC Realm.
 >>>>
 >>>> Basically what I want is for users to be able to see who's currently
 >>>> online (other users).
 >>>>
 >>>> Is there a simple way of approaching this?
 >>>> and if I were to have to write something for myself, to say, keep
 >>>> track of all the users who logged in, is there an event which is
 >>>> fired when a user's session is invalidated so I remove him from a
 >>>> master "logged-in" user list?
 >>>>
 >>>>
 >>>> Thanks for your help everyone..
 >>>>
 >>>>
 >>>> Terrence Szeto
 >>>> Cybermation Web Architect
 >>>>
 >>>> _________________________________________________________________
 >>>> Join the world's largest e-mail service with MSN Hotmail.
 >>>> http://www.hotmail.com
 >>>>
 >>>>
 >>>> --
 >>>> To unsubscribe, e-mail:
 >>>> <mailto:[EMAIL PROTECTED]>
 >>>> For additional commands, e-mail:
 >>>> <mailto:[EMAIL PROTECTED]>
 >>>>
 >>>>
 >>>
 >>>
 >>>
 >>>
 >>> --
 >>> To unsubscribe, e-mail:
 >>> <mailto:[EMAIL PROTECTED]>
 >>> For additional commands, e-mail:
 >>> <mailto:[EMAIL PROTECTED]>
 >>>
 >>>
 >>>
 >>
 >>
 >>
 >> --
 >> To unsubscribe, e-mail:
 > <mailto:[EMAIL PROTECTED]>
 >> For additional commands, e-mail:
 > <mailto:[EMAIL PROTECTED]>
 >>
 >
 >
 > --
 > To unsubscribe, e-mail:
 > <mailto:[EMAIL PROTECTED]>
 > For additional commands, e-mail:
 > <mailto:[EMAIL PROTECTED]>
 >
 > _________________________________________________________________
 > MSN Photos is the easiest way to share and print your photos:
 > http://photos.msn.com/support/worldwide.aspx
 >
 >
 > --
 > To unsubscribe, e-mail:   
<mailto:[EMAIL PROTECTED]>
 > For additional commands, e-mail: 
<mailto:[EMAIL PROTECTED]>
 >


--
To unsubscribe, e-mail:   
<mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: 
<mailto:[EMAIL PROTECTED]>

_________________________________________________________________
Send and receive Hotmail on your mobile device: http://mobile.msn.com


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to