Sturts 2会话失效,将请求会话设置为新会话 [英] Sturts 2 session invalidation with setting request session to a new session

查看:183
本文介绍了Sturts 2会话失效,将请求会话设置为新会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

  getHttpServletRequest()。getSession()。invalidate(); 

我创建了一个新会话

  getHttpServletRequest()的getSession(真)。 

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



getSession()返回map在我的动作类中我实现 SessionAware ,其中包含 setSession(地图会话)



编辑:以下是例外

 创建HttpSession到期时出错响应被提交给客户。在将结果呈现给客户端之前,您可以使用CreateSessionInterceptor或从您的操作创建HttpSession:HttpSession无效
java.lang.IllegalStateException:HttpSession无效

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



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

解决方案

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

  SessionMap session =(SessionMap)ActionContext.getContext()。getSession(); 

//
session.invalidate();

//续订servlet会话
session.put(renewServletSession,null);
session.remove(renewServletSession);

//填充struts会话
session.entrySet();

现在,struts会话已准备好使用新的servlet会话,并准备好重用struts会话。 / p>

In my Struts application once an user login I need to invalidate the current session and create a new session. I invalidate the session with

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

And I create a new session as

getHttpServletRequest().getSession(true);

The problem here is after above I try to access getSession() it gives the state invalid exception; HttpSession is invalid.

getSession() returns a map where in my action class I implements SessionAware which has the setSession(Map session).

EDIT: Below is the exception

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

So, what I assume the problem is the Struts getSession() still reference the session which I've invalidated.

How to make the Struts getSession() to reference the new session which I've created?

解决方案

If you want to access the struts session after you invalidated the servlet session you should update or renew the struts session. For example

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();

now struts session is ready to use the new servlet session and you ready to reuse the struts session.

这篇关于Sturts 2会话失效,将请求会话设置为新会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆