Session listener

The session listener works on the creation of the web session and also destroys it. Here's a simple example that logs the two events:

@WebListener
public class SampleSessionListener implements HttpSessionListener {
private static final Logger logger = getLogger(SampleSessionListener.class.getName());
@Override
public void sessionCreated(HttpSessionEvent se) {
logger.info("MySessionListener.sessionCreated: " + se.getSession().getId());
}
@Override
public void sessionDestroyed(HttpSessionEvent se) {
logger.info("MySessionListener.sessionDestroyed: " + se.getSession().getId());
}
}

Each listener must declare the javax.servlet.annotation.WebListener annotation. The session listener must implement the javax.servlet.http.HttpSessionListener interface.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.61.142