title: spring java: interceptor sendRedirect loop
body: <p>i implemented a Interceptor that do certain checks and sendRedirect to some page. currently im testing it without any conditions, just simply sendRedirect when preHandle is called. this is my implementation:</p>
  
  <pre><code>class HttpInterceptorMgr implements HandlerInterceptor {
      public boolean preHandle(HttpServleRequest aRequest, HttpServletResponse aResponse, Object aHandler) {
       try {
        sendRedirect("/somepage");
        return false;
       }
       catch(Exceptio n e) {
        // Do something else
       }
      }
  }
  </code></pre>
  
  <p>web.xml</p>
  
  <pre><code>&lt;servlet-mapping&gt;
   &lt;servlet-name&gt;myproject&lt;/servlet-name&gt;
   &lt;url-pattern&gt;/&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  
  ....
  &lt;filter&gt;
   &lt;filter-name&gt;springSecurityFilterChain&lt;/filter-name&gt;
   &lt;filter-class&gt;org.springframework.web.filter.DelegatingFilterProxy&lt;/filter-class&gt;
  &lt;/filter&gt;
  
  &lt;filter-mapping&gt;
   &lt;filter-name&gt;springSecurityFilterChain&lt;/filter-name&gt;
   &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
  &lt;/filter-mapping&gt;
  ...
  </code></pre>
  
  <p>myproject-web-servlet.xml</p>
  
  <pre><code>&lt;mvc:annotation-driven /&gt;
  &lt;mvc:resources mapping="/resources/**" location="/resources/" /&gt;
  &lt;mvc:resources mapping="/js/**" location="/js/" /&gt;
  &lt;mvc:resources mapping="/css/**" location="/css/" /&gt;
  &lt;mvc:resources mapping="/images/**" location="/images/" /&gt;
  
  &lt;mvc:interceptors&gt;
   &lt;bean class="org.mycompany.HttpInterceptorMgr" /&gt;
  &lt;/mvc:interceptors&gt;
  </code></pre>
  
  <p>applicationContextSecurityBeans.xml</p>
  
  <pre><code>&lt;security:http auto-config="true" use-expression="true" access-denied-page="/user/denied"&gt;
   &lt;security:form-login
     login-page="/login"
     authentication-failure-url="login?error=true"
     default-target-url="/homepage" /&gt;
   &lt;security:logout invalidate-session="true"
     logout-success-url="/login"
     logout-url="/j_sring_security_logout" /&gt;
  &lt;/security:http&gt;
  </code></pre>
  
  <p>the problem i'm facing is that my page gets redirect in a loop. on firefox browser, it says "the page isn't redirectly properly". i tail catalina.out and it shows it enter prehandle multiple times and its request.getRequestUrl is <code>/somepage</code>. but im not able to reach the page successfully.</p>