struts2监听器session失效时的操作

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

}

}

你可能感兴趣的:(java,session)