Sturts 2会话失效,将请求会话设置为新会话

在我的Struts应用程序中,一旦用户登录,我需要使当前会话无效并创建新会话。 我用会话使会话无效

getHttpServletRequest().getSession().invalidate(); 

我创建了一个新会话

 getHttpServletRequest().getSession(true); 

这里的问题是在上面我尝试访问getSession()它给出了状态无效exception; HttpSession无效。

getSession()返回一个map,在我的action类中我实现了SessionAware ,它有setSession(Map session)

编辑:以下是例外

 Error creating HttpSession due response is commited to client. You can use the CreateSessionInterceptor or create the HttpSession from your action before the result is rendered to the client: HttpSession is invalid java.lang.IllegalStateException: HttpSession is invalid 

所以,我认为问题是Struts getSession()仍然引用我已经失效的会话。

如何让Struts getSession()引用我创建的新会话?

如果要在使servlet会话无效后访问struts会话,则应更新或更新struts会话。 例如

 SessionMap session = (SessionMap) ActionContext.getContext().getSession(); //invalidate session.invalidate(); //renew servlet session session.put("renewServletSession", null); session.remove("renewServletSession"); //populate the struts session session.entrySet(); 

现在,struts会话已准备好使用新的servlet会话,并且您已准备好重用struts会话。