繁体   English   中英

服务器重启后HttpSession仍然存在

[英]HttpSession remains after server restart

我正在学习春天。 执行登录/注销功能。 这就是我的控制器的样子:

@RequestMapping(value="/successfulLoginAuth", method=RequestMethod.GET)
public ModelAndView postHttpLogin(HttpSession session, Authentication authInfo) 
{

ModelAndView mav = new ModelAndView();
mav.setViewName("redirect:/index.html");
session.setAttribute("authInfo", authInfo);

return mav;

}

登录是通过Spring Security使用我实现的dao服务执行的。 这很好。

这是index.jsp的内容:

<% 
    HttpSession session1 = request.getSession(false);
    Authentication authInfo; 
    if( (session1 != null) && 
        ( (authInfo = (Authentication)session1.getAttribute("authInfo")) != null) 
      )
    {

        out.print(" yo " + authInfo.getName() + " " + authInfo.getAuthorities().iterator().next().getAuthority());
    }
    else
    {
%>    
<a href="${pageContext.request.contextPath}/registration">New? Sign Up!</a><br/>

<a href="${pageContext.request.contextPath}/login">Existing? Sign In!</a><br/>
<%} %>

当我登录并重新启动服务器时,我仍然登录。在服务器重启后,会话信息是否应该丢失? 如果我重新启动浏览器,它将按预期工作(即会话信息丢失)。

这是我的Spring Security配置:

<http auto-config="true"  use-expressions="true">
        <intercept-url pattern="/" access="permitAll" />
        <intercept-url pattern="/logout" access="permitAll" />
        <intercept-url pattern="/accessdenied" access="permitAll" />
        <form-login login-page="/login" default-target-url="/successfulLoginAuth" authentication-failure-url="/accessdenied" />
        <logout logout-success-url="/logout" />
    </http>

<authentication-manager>
    <authentication-provider user-service-ref="myUserDetailsService"></authentication-provider>
  </authentication-manager>

我假设您正在使用Tomcat ,它使用Manager组件在应用程序生命周期之间保持会话。 您可以在Manager组件配置中更改所有这些设置。

认为这也取决于你做的改变。 Eclipse的Tomcat服务器插件将决定是否应该刷新序列化的HttpSession

我猜你正在使用Tomcat,

来自Docs SaveOnRestart属性

Should all sessions be persisted and reloaded when Tomcat is shut down and restarted (or when this application is reloaded)? By default, this attribute is set to true.

您可以通过在context.xml中将属性更改为false来控制此操作

<Manager pathname="">
      <saveOnRestart>false</saveOnRestart>
</Manager> 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM