2017-08-29 73 views
0

我有一個Singleton對象,它保存了基於「Spring」的儀表板所需的所有數據。我將這個單例對象存儲在我登錄時從控制器接收到的httpservlet請求中。如何防止session.attribute在eclipse重新加載apache時變爲null

servlet.getSession().setAttribute(SESSION_DATA, sessionData); 

一旦我已經登錄我檢查,看看是否sessionData已成爲空,並嘗試從servlet.session.attribute檢索。但是從servlet.session.attribute所有屬性成爲空

  • 每隔幾分鐘我的Apache(通過日食)當我保存源文件

  • 自動加載是否有辦法防止session.attribute成爲空值 ?

     if (sessionData == null) 
          if (httpServlet != null && httpServlet.getSession() != null 
            && httpServlet.getSession().getAttribute(SESSION_DATA) != null) { 
           log.info("Recovering sessionData from http session"); 
           sessionData = (SessionDataManager) httpServlet.getSession().getAttribute(SESSION_DATA); 
          } else { 
           log.warn((httpServlet == null) ? "httpServlet is null" : "httpServlet is not null"); 
           if (httpServlet != null) { 
            log.warn((httpServlet.getSession() == null) ? "httpServlet.getSession is null" 
              : "httpServlet.getSession is not null"); 
            if (httpServlet.getSession() != null) 
             log.warn((httpServlet.getSession().getAttribute(SESSION_DATA) == null) 
               ? "httpServlet.getSession.getAttribute(SESSION_DATA) is null" 
               : "httpServlet.getSession.getAttribute(SESSION_DATA) is not null"); 
    
           } 
          } 
    
  • +0

    我們不能使用會話範圍的spring bean,而不是設置session屬性。 – ArslanAnjum

    +0

    請你詳細說明一下嗎?或者給我一個我可以使用的鏈接。 – Siddharth

    回答

    0

    我編輯我web.xml添加以下行,以增加超時我會死。

    我注意到onDestroy被調用,並且讀取doFilter在沒有線程訪問過濾器之後調用。因此增加超時是爲我工作的解決方案之一。

    <session-config> 
         <session-timeout>10</session-timeout> 
    </session-config> 
    

    該值以分鐘爲單位。將其設置爲無限制將值設置爲-1

    相關問題