Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Obtaining a list of all active sessions within a Servlet container.

Reply
Thread Tools

Obtaining a list of all active sessions within a Servlet container.

 
 
theog
Guest
Posts: n/a
 
      04-14-2008
Hi,

I would like to obtain a list of sessions. Old way was to look at
HttpSessionContext, however that is deprecated.

Would be great if someone can share an example of how I would
accomplish this!

Cheers,
Theo
 
Reply With Quote
 
 
 
 
sd.balasubramani@gmail.com
Guest
Posts: n/a
 
      04-14-2008
Hi Theo,

Use HttpSessionActivationListener as follows for your requirement,

<<

class SessionCounterListener implements HttpSessionActivationListener
{

public static final Map activeSessions = HashMap<String,
HttpSession>();

public void sessionDidActivate(HttpSessionEvent event) {
HttpSession session = event.getSession();
activeSessions.put(session.getId(), session);
}

public void sessionWillPassivate(HttpSessionEvent event) {
HttpSession session = event.getSession();
activeSessions.remove(session.getId();
}

}

>>


Define the above listener in web.xml as,
<listener>
<listener-class>my.package.SessionCounterListener</listener-class>
</listener>

Use below code to get the active sessions,

SessionCounterListener.activeSessions.size() - Returns the number of
active sessions.
SessionCounterListener.activeSessions.getValues() - Returns the all
the active sessions.

Regards,
Bala.

http://rest-client.googlecode.com/

 
Reply With Quote
 
 
 
 
Robert Klemme
Guest
Posts: n/a
 
      04-14-2008
On 14.04.2008 09:41, wrote:
> Hi Theo,
>
> Use HttpSessionActivationListener as follows for your requirement,
>
> <<
>
> class SessionCounterListener implements HttpSessionActivationListener
> {
>
> public static final Map activeSessions = HashMap<String,
> HttpSession>();
>
> public void sessionDidActivate(HttpSessionEvent event) {
> HttpSession session = event.getSession();
> activeSessions.put(session.getId(), session);
> }
>
> public void sessionWillPassivate(HttpSessionEvent event) {
> HttpSession session = event.getSession();
> activeSessions.remove(session.getId();
> }
>
> }
>
>
> Define the above listener in web.xml as,
> <listener>
> <listener-class>my.package.SessionCounterListener</listener-class>
> </listener>
>
> Use below code to get the active sessions,
>
> SessionCounterListener.activeSessions.size() - Returns the number of
> active sessions.
> SessionCounterListener.activeSessions.getValues() - Returns the all
> the active sessions.


.... and don't forget proper synchronization.



robert
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Getting All Active Web Sessions Atul ASP .Net 3 08-22-2006 11:04 AM
servlet help - redirecting from within a framed servlet ppcguy Java 1 08-08-2005 03:03 PM
Please help me create a list of all active sessions? Christina N ASP .Net 2 09-15-2004 07:28 PM
Servlet question(Tomcat, web.xml, servlet-class, servlet-name) circuit_breaker Java 2 04-04-2004 03:26 AM
Can I get all the sessions currently active? Dustin Aleksiuk ASP .Net 3 11-11-2003 03:02 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57