aspose file tools*
The moose likes Servlets and the fly likes How to get the list of existing sessions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to get the list of existing sessions" Watch "How to get the list of existing sessions" New topic
Author

How to get the list of existing sessions

Tanveer Rameez
Ranch Hand

Joined: Dec 11, 2000
Posts: 158
hi All,
I am using some methods which are deprecated in Java Servlet API 2.1. I want to find the alternative, but the description in javadoc says that : Deprecated. As of Java Servlet API 2.1 with no replacement.
I want to get the reference of all the existing (valid) sessions that has been created when the doGet or doPost of that servlet is invoked by a HttpServletRequest. I used HttpSessionContext.getSessionContext(); and from I obtain the enumeration of session IDs. but the method is deprecated.
Kindly let me know of nay alternative to get the list of sessions. I need the solution fast.
regards and thanks in advance
Tanveer

Basically what I want to do is to restrict only one session from one IP (machine) at a time. The simplified code is somewhat like this:

[ September 12, 2002: Message edited by: Tanveer Rameez ]

Author of JPhotoBrush Pro (www.jphotobrushpro.com)
Hartmut Ludwig
Ranch Hand

Joined: Aug 31, 2002
Posts: 51
Originally posted by Tanveer Rameez:
I used HttpSessionContext.getSessionContext(); and from I obtain the enumeration of session IDs. but the method is deprecated.
Kindly let me know of nay alternative to get the list of sessions. I need the solution fast.

Hi, Tanveer,
I've encounterd a similar problem and have not solved it yet, but I think I just found the solution on the webpage of More Servlets and JavaServer Pages. Go to
Chapter 10 and locate the sourcecode for SessionCounter.java.
This class is an exampe for a Session Listener (available since Servlet 2.3) which offers the following 2 methods:
public void sessionCreated(HttpSessionEvent event)
public void sessionDestroyed(HttpSessionEvent event)
Those can be used to get some Information about the sessions. Like described in this example you can save the relevant information in the servlet context and make it available to the servlet.
Hope it helps, I will try it out tonight...
Hartmut
[ September 12, 2002: Message edited by: Hartmut Ludwig ]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to get the list of existing sessions