public class LogoutListener implements HttpSessionAttributeListener {
private static final Log log = LogFactory.getLog(LogoutListener.class);
public void attributeAdded(HttpSessionBindingEvent event) {
log.info("add attribute to session");
System.out.println("add attribute to session");
}
?
public void attributeRemoved(HttpSessionBindingEvent event) {
? ?log.info("remove attribute from session");
? ?System.out.println("remove attribute from session");
? ?if (Constants.USER_KEY.equals(event.getName())) {
? ? ? User user = (User) event.getValue();
? if (user != null) {
? ApplicationContext ctx = WebApplicationContextUtils
? ? ? ? ?.getWebApplicationContext(event.getSession()
? ? ? ? .getServletContext());
? ? ? UserService userService = (UserService) ctx
.getBean("userServiceImpl");
//对用户进行操作,比如调用service的方法修改用户在线状态为不在线状态
}
}
}
}
public void attributeReplaced(HttpSessionBindingEvent event) {
/*log.info("replace attribute from session");
System.out.println("replace attribute from session");*/
}
}