title: Interceptor preHandle() not redirecting to login.html
body: <p>I have a spring application. I introduced a sessionInterceptor to prevent direct access to index.jsp. If the user is not logged in it shouldn't be able to access index.jsp and should be redirected to login.html. The code is hitting the preHandle() method and running all the code but after <code>return false</code> it's not redirecting to login.html. What's wrong? Any gurus out there for help? Thanks in advance.</p>
  
  <p>My preHandle() in SessionInterceptor.java is:</p>
  
  <pre><code>public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
  
          HttpSession session = request.getSession();
  
          // if displaying the home page, make sure the user is reloaded.
          if (request.getRequestURI().endsWith("login.html")) {
              session.removeAttribute("isUserLoggedIn");
          }
  
          if (session.getAttribute("isUserLoggedIn") == null &amp;&amp; !request.getRequestURI().endsWith("login")) {
              response.sendRedirect(request.getContextPath() + "/login.html");
              return false;               
          }
          return true;
      }
  </code></pre>
  
  <p>I have tried the following as well but all in vain.</p>
  
  <pre><code>RequestDispatcher dispatcher = request.getServletContext().getRequestDispatcher("/login.html");
                  dispatcher.forward(request, response);
  </code></pre>
  
  <p>My dispatcher-servlet.xml settings are:</p>
  
  <pre><code>&lt;bean id="sessionInterceptor" class="com.xxx.xxx.xxx.SessionInterceptor" /&gt;
  &lt;bean id="annotationMapper" class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"&gt;
      &lt;property name="interceptors"&gt;
          &lt;list&gt;
              &lt;ref bean="sessionInterceptor" /&gt;
          &lt;/list&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  
  &lt;!-- Configures Handler Interceptors --&gt;
  &lt;mvc:interceptors&gt;
      &lt;bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor" /&gt;
      &lt;mvc:interceptor&gt;
          &lt;mvc:mapping path="/**" /&gt;
          &lt;bean class="com.xxx.xxx.xxx.SessionInterceptor" /&gt;
      &lt;/mvc:interceptor&gt;
  &lt;/mvc:interceptors&gt;
  </code></pre>
  
  <p>The web.xml is:</p>
  
  <pre><code>  &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;dispatcher&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/rest/*&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;
    &lt;welcome-file-list&gt;
      &lt;welcome-file&gt;login.html&lt;/welcome-file&gt;
    &lt;/welcome-file-list&gt;
  </code></pre>