簡體   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