![]() ![]() | ||||||||||||||||||
| Home>>>> | ||||||||||||||||||
Java Servlet Pages and ServletsSession ListenersYou 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>
| ||||||||||||||||||