title: How To Handle session using Interceptor in Spring 3
body: <p>I Want to redirect to login whenever the session goes invalid.My servelt.xml is as follows.</p>
  
  <pre><code>&lt;mvc:interceptors&gt;
    &lt;bean class="com.package.login.LoginIntercepter" /&gt;
  &lt;/mvc:interceptors&gt;
  </code></pre>
  
  <p>Interceptor :</p>
  
  <pre><code>public boolean preHandle(HttpServletRequest request,
          HttpServletResponse response, Object handler) throws Exception {
      HttpSession session = request.getSession();
      HashMap details = (HashMap)session.getAttribute("details");
      System.out.println("Pre-handle ::"+request.getRequestURI());
      if(details!=null){
          /*For Checking the Session
           * -----Start-----*/
                  return true;
      }else{
         response.sendRedirect("Login");//Here Login is action Name which is Mapped in Login Controller
         return false;
      }
   }
  </code></pre>
  
  <p>Login Controller :</p>
  
  <pre><code>@RequestMapping(value="/Login", method=RequestMethod.GET)
  public String loginMethodWithoutaction(HttpServletRequest request,HttpServletResponse response)
  {
      String page="login";
      HttpSession session = request.getSession();
      HashMap details = (HashMap)session.getAttribute("details");
      if(details!=null)
          page = "redirect:/Home";
      return page;
  }
  </code></pre>
  
  <p>If Session is invalid then it has to redirect "login" page. otherwise it has to go Home Controller.But its not working.Whenever application get started, the message get printed multiple times and at the end it gives stack overflow.</p>