0

当 JSF 应用程序关闭或 tomact 关闭时,我需要使活动会话对象无效并清理。以下是我在 application scoped bean 中编写的代码

@PreDestroy
public void shutdown(){

Map appMap = FacesContext.getCurrentInstance().getExternalContext().getApplicationMap();
Map<String,HttpSession> userSessionMap=(Map<String,HttpSession>)appMap.get("USERS");
log.info("userSessionMap " + userSessionMap);
Set<Entry<String, HttpSession>> entrySet = userSessionMap.entrySet();
for(Entry<String, HttpSession> entry:entrySet){
    HttpSession session = entry.getValue();
    log.info("HttpSession " + session.getId() + " calling invalidate");
    session.invalidate();
}
  }

并且以下被覆盖 HttpSessionListener

@Override
public void sessionDestroyed(HttpSessionEvent se){

HttpSession session = se.getSession();
String id = session.getId();
LoginActionController controller = (LoginActionController) session.getAttribute("userInfo");
log.info("HttpSession " + id + ", LoginActionController " + controller + " is being destroyed...");
if(controller != null){
    log.info("User " + controller.getUserName() + " is logged out");
    String userName = controller.getUserName();
    ServletContext context = session.getServletContext();
    Object obj = context.getAttribute("USERS");
    if(obj instanceof Map){
    Map map = (Map) obj;
    map.remove(userName);
        RWFacade rWFacade =(RWFacade)session.getAttribute("rWFacade");
        rWFacade.closeFacade();
    }

}
}

运行此代码时

session.invalidate();

没有被执行。我错过了什么?谢谢。

4

1 回答 1

1

要在 tomcat 中重新启动时禁用会话持久性,您可以取消注释 $TOMCAT_HOME/conf/context.xml 中的配置

<!-- Uncomment this to disable session persistence across Tomcat restarts

    <Manager pathname="" /> -->

也许它会帮助你。

于 2012-08-21T08:14:18.853 回答