Sturts 2 session invalidation with setting request session to a new session(通过将请求会话设置为新会话来使 2 会话失效)
问题描述
在我的 Struts 应用程序中,一旦用户登录,我需要使当前会话无效并创建一个新会话.我使会话无效
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();
我创建了一个新会话
getHttpServletRequest().getSession(true);
这里的问题是在上面我尝试访问 getSession()
之后它给出了状态无效异常;HttpSession
无效.
The problem here is after above I try to access getSession()
it gives the state invalid exception; HttpSession
is invalid.
getSession()
返回一个映射,在我的操作类中我实现了 SessionAware
,它具有 setSession(Map session)
.
getSession()
returns a map where in my action class I implements SessionAware
which has the 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()
仍然引用我已失效的会话.
So, what I assume the problem is the Struts getSession()
still reference the session which I've invalidated.
如何让 Struts getSession()
引用我创建的新会话?
How to make the Struts getSession()
to reference the new session which I've created?
推荐答案
如果要在使 servlet 会话无效后访问 struts 会话,则应更新或更新 struts 会话.例如
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();
现在 struts 会话已准备好使用新的 servlet 会话,并且您已准备好重用 struts 会话.
now struts session is ready to use the new servlet session and you ready to reuse the struts session.
这篇关于通过将请求会话设置为新会话来使 2 会话失效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:通过将请求会话设置为新会话来使 2 会话失效


基础教程推荐
- 如何在 Spring @Value 注解中正确指定默认值? 2022-01-01
- 验证是否调用了所有 getter 方法 2022-01-01
- 多个组件的复杂布局 2022-01-01
- 从 python 访问 JVM 2022-01-01
- 在 Java 中创建日期的正确方法是什么? 2022-01-01
- Java Swing计时器未清除 2022-01-01
- 如何在 JFrame 中覆盖 windowsClosing 事件 2022-01-01
- 不推荐使用 Api 注释的描述 2022-01-01
- 大摇大摆的枚举 2022-01-01
- Java 实例变量在两个语句中声明和初始化 2022-01-01