title: Login Filter causing redirect loop
body: <p>I am creating a simple web application using servlets and JSP. I am implementing a Filter which checks if the user has logged in already, literally checks if the user session is alive. If the session is not alive, then the user has to be redirected to the login page (index,jsp)</p>
  
  <p>This is my filter mapping in the web.xml file</p>
  
  <pre><code> &lt;web-app xmlns...&gt;
    &lt;display-name&gt;FilterTest&lt;/display-name&gt;
    &lt;welcome-file-list&gt;
      &lt;welcome-file&gt;index.jsp&lt;/welcome-file&gt;
    &lt;/welcome-file-list&gt;
    &lt;filter&gt;
      &lt;filter-name&gt;LoginFilter&lt;/filter-name&gt;
      &lt;filter-class&gt;LoginFilter&lt;/filter-class&gt;
    &lt;/filter&gt;
    &lt;filter-mapping&gt;
      &lt;filter-name&gt;LoginFilter&lt;/filter-name&gt;
      &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
    &lt;/filter-mapping&gt;
    &lt;servlet&gt;
      &lt;description&gt;&lt;/description&gt;
      &lt;servlet-name&gt;LoginController&lt;/servlet-name&gt;
      &lt;servlet-class&gt;LoginController&lt;/servlet-class&gt;
    &lt;/servlet&gt;
    &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;LoginController&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/LoginController&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <p>When the user tries to access a different page, then the LoginFilter checks for the session. If the session is alive the user is redirected to the requested page else redirected to index.jsp.</p>
  
  <p>The problem I am facing here is, the <code>LoginFilter</code> checks for the session even when the user is logging in ( request comes from the <code>index.jsp</code> which is the login page).
  So what I see here is, When the user logs in, the control goes to the <code>LoginFilter</code>, since the session is not yet created for this user, he is redirected back to login page which is creating a indefinite redirect loop.</p>
  
  <p>I want to exclude the filter checking/session checking if the request is coming from <code>index.jsp</code>. </p>
  
  <p>Is there any way in which I can accomplish this ? Or any way by which I can identify if the requesting page is <code>index.jsp</code> ?</p>
  
  <p><strong>UPDATE:</strong> The url when the application starts up is <code>http://servername:port/FilterTest</code>
  Here the index.jsp is loaded.</p>
  
  <p>I am validating the login in <code>LoginController</code> servlet which redirects the user to home.jsp (welcome page) if the login was successful.</p>
  
  <p>Thanks..!</p>