Thank you very much for your reply.
I tried to implement ur suggestion. I was getting following errors.
I am using Oracle 10g application server. I guess it supports j2ee1.3 and I have seen that servlet specification in j2ee1.3 should support HttpSessionListener.
This is my servlet class.
------------------
package demo.servlets;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import demo.utility.Constants;
import com.utilities.logging.MyLogger;
import com.utilities.logging.LoggingFactory;
public class ManageSessions extends HttpServlet implements HttpSessionListener {
HashMap userSessions = null;
//MyLogger logger = null;
public void init(ServletConfig config) throws ServletException{
userSessions = new HashMap();
(config.getServletContext()).setAttribute("userSessions",userSessions);
System.out.println("In Servlet Init");
}
//Notification that a session was created
public void sessionCreated(HttpSessionEvent se) {
if(userSessions == null)
userSessions = new HashMap();
String userName =
((demo.vo.UserVO)((se.getSession()).getAttribute(Constants.USERKEY))).getUserName();
/*
if(logger == null)
logger = LoggingFactory.getLogger(this,"safari");
logger.debug("User "+userName+" has logged into the system");
*/
userSessions.put(userName,se.getSession());
System.out.println("In Session Created User Hashmap:"+userSessions);
}
//Notification that a session was invalidated
public void sessionDestroyed(HttpSessionEvent se) {
String userName =
((demo.vo.UserVO)((se.getSession()).getAttribute(Constants.USERKEY))).getUserName();
/*
if(logger == null)
logger = LoggingFactory.getLogger(this,"safari");
logger.debug("User "+userName+" has logged out of the system");
*/
if(userSessions != null){
userSessions.remove( (se.getSession()).getAttribute(Constants.USERKEY));
}
System.out.println("In Session Removed User Hashmap:"+userSessions);
}
}
------------------
In the program, I am trying to hold sessions in a Hashmap and remove sessions from the Hashmap on session inactivate/expire/logout.
I initially thought of initializing all my variables in init method. I am not sure if init is being called. Hence I had to initialize in sessionCreated and sessionDestroyed methods. In my web.xml file I added following entries.
-----------------
<listener>
<listener-class>demo.servlets.ManageSessions</listener-class>
</listener>
-----------------
when I deploy my application in the Application server, I am able to see the println statements from sessionDestroyed but not from sessionCreated.
In my LogonAction.java class, I am creating session using request.getSession(); method. I guess it should generate sessionCreatedEvent.
Please help me out in solving this problem. I have been working on this since this afternoon and I am now like
.
I will really approciate if you provide some documentation on this concept
Thank you very much inadvance. early replys would be greatly appreciated.
Thank you
Saritha
[ September 13, 2004: Message edited by: Saritha ventrapragada ]