package com.beltino.communitymedical.test;
import javax.servlet.http.*;
import org.apache.log4j.Logger;
import java.util.*;
public class SessionListener extends HttpServlet implements HttpSessionListener, HttpSessionAttributeListener {
static Logger appLog=Logger.getLogger(SessionListener.class);
private Date getNow(){
Calendar cal=Calendar.getInstance();
return cal.getTime();
}
//Notification that a session was created
public void sessionCreated(HttpSessionEvent se) {
appLog.info("创建了一个Session,SessionID=" + se.getSession().getId()+",时间为="+getNow());
}
//Notification that a session was invalidated
public void sessionDestroyed(HttpSessionEvent se) {
appLog.info("销毁了一个Session,SessionID=" + se.getSession().getId()+",时间为="+getNow());
}
//Notification that a new attribute has been added to a session
public void attributeAdded(HttpSessionBindingEvent se) {
appLog.info("Sessionid="+se.getSession().getId()+":增加了一个属性值,Name="+se.getName()+",Value="+se.getValue()+",时间为="+getNow());
}
//Notification that an attribute has been removed from a session
public void attributeRemoved(HttpSessionBindingEvent se) {
appLog.info("Sessionid="+se.getSession().getId()+":删除了一个属性值,Name="+se.getName()+",Value="+se.getValue()+",时间为="+getNow());
}
//Notification that an attribute of a session has been replaced
public void attributeReplaced(HttpSessionBindingEvent se) {
appLog.info("Sessionid="+se.getSession().getId()+":替换了一个属性值,Name="+se.getName()+",Value="+se.getValue()+",时间为="+getNow());
appLog.info("Sessionid="+se.getSession().getId()+":现在的属性值,Name="+se.getName()+",Value="+se.getSession().getAttribute(se.getName()));
}
}