2017-08-29 26 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

    相关问题