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

时间:2013-06-24 07:52:54

标签: java struts2 httpsession

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

使会话无效
getHttpServletRequest().getSession().invalidate();

我创建了一个新的会话

getHttpServletRequest().getSession(true);

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

getSession()返回一个地图,在我的操作类中,我实现了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()引用我创建的新会话?

1 个答案:

答案 0 :(得分:9)

如果要在使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会话。

相关问题