欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

struts2监听器session失效时的操作

程序员文章站 2022-03-03 08:59:59
...

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

}

}

相关标签: session java