title: Handle Session timeout?
body: <p>How to handle session timeout in spring mvc 3.2 for example after 30 mins it should redirect to index.html.</p>
  
  <p>Tried with interceptor but session time out values specified in web.xml got ignored.</p>
  
  <p>spring-servlet.xml</p>
  
  <pre><code> &lt;mvc:interceptors&gt;   
     &lt;bean class="com.server.utils.AuthenticationTokenInterceptor" /&gt;   
     &lt;/mvc:interceptors&gt;
  </code></pre>
  
  <p>web.xml</p>
  
  <pre><code>&lt;session-config&gt;
      &lt;session-timeout&gt;30&lt;/session-timeout&gt;
    &lt;/session-config&gt;
  
   @Override  
      public boolean preHandle(HttpServletRequest request,HttpServletResponse response, Object handler) throws Exception {   
       try  
          {System.out.println("Inside Interceptor");   
              HttpSession session = request.getSession();   
              String authToken = (String) session.getAttribute("userId");   
                 System.out.println("Interceptor invoked For Auth token");   
                  if(authToken==null || authToken.equals(""))   
                  {   
                      System.out.println("Auth Token time Out");   
                   response.sendRedirect(servletContext.getContextPath()+"/login");   
                      return false;   
                  }   
                  else  
                  {   
                   return true;   
                  }   
         }catch(Exception ex)   
             {   
             ex.getMessage();   
            response.sendRedirect(servletContext.getContextPath()+"/login");   
                return false;   
             }   
          }   
  
  
      @Override  
      public void postHandle(HttpServletRequest request,   
            HttpServletResponse response, Object handler,   
          ModelAndView modelAndView) throws Exception {   
     }   
  
     @Override  
   public void afterCompletion(HttpServletRequest request,   
           HttpServletResponse response, Object handler, Exception ex)   
              throws Exception {   
      }
  </code></pre>