Home>>>>

Java Servlet Pages and Servlets

Session Listeners

You can add event listeners on session creation and session deletion

The following example creates a SessionVariables instance and adds it into the session.

      
public class SessionVariablesSessionListener implements HttpSessionListener {
    public void sessionCreated(HttpSessionEvent httpSessionEvent) {
        httpSessionEvent.getSession().setAttribute(SessionVariables.KEY, new SessionVariables());
    }

    public void sessionDestroyed(HttpSessionEvent httpSessionEvent) {
    }
}
      
    

The webapp's web.xml must also be updated:

    ...
  <listener>
    <description>Session listener</description>
    <display-name>Session listener</display-name>
    <listener-class>com.magicmonster.intranet.web.struts.SessionVariablesSessionListener</listener-class>
  </listener>
</web-app>
    
More Articles (showing 7 below)  
 2007-11-28
 2006-08-20
 2006-05-07
 2006-03-04
 2006-01-07
 2005-11-03
 2004-05-20 2008-01-07