struts2监听器session失效时的操作_JAVA_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > JAVA > struts2监听器session失效时的操作

struts2监听器session失效时的操作

 2014/4/16 18:28:52  liujiaoshui  程序员俱乐部  我要评论(0)
  • 摘要:publicclassLogoutListenerimplementsHttpSessionAttributeListener{privatestaticfinalLoglog=LogFactory.getLog(LogoutListener.class);publicvoidattributeAdded(HttpSessionBindingEventevent){log.info("addattributetosession");System.out.println
  • 标签:操作 监听 struts

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");*/

}

}

发表评论
用户名: 匿名