gpt4 book ai didi

java - Struts 2 session 失效,将请求 session 设置为新 session

转载 作者:行者123 更新时间:2023-12-02 06:16:20 29 4
gpt4 key购买 nike

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

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

我创建了一个新 session

getHttpServletRequest().getSession(true);

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

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

编辑:以下是异常(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

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

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

最佳答案

如果您想在使 servlet session 失效后访问 struts session ,您应该更新或更新 struts session 。例如

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 session 已准备好使用新的 servlet session ,并且您已准备好重用 struts session 。

关于java - Struts 2 session 失效,将请求 session 设置为新 session ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17270484/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com