title: Why My Java Spring MVC Servlet Filter Is Not Intercepting Incoming HttpRequest?
body: <p>I'm debugging and existing Spring MVC project, I added a servlet filter [ ServletFilter ], which I intended to intercept all incoming httprequests, but how come only some requests are intercepted, most are not ? What should I do to intercept all incoming requests ?</p>
  
  <p>My servlet filter looks like this :</p>
  
  <pre><code>import ...
  
  public class ServletFilter implements Filter
  {    
    public void init(FilterConfig filterConfig) throws ServletException { }
  
    public void doFilter(ServletRequest servletRequest,ServletResponse servletResponse,FilterChain filterChain) throws IOException,ServletException
    {
      ...
    }
  }
  </code></pre>
  
  <p>My Java web app's web.xml looks like this :</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"&gt;
   &lt;context-param&gt;
    &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
    &lt;param-value&gt;/WEB-INF/classes/applicationContext.xml&lt;/param-value&gt;
   &lt;/context-param&gt;
   &lt;listener&gt;
    &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt;
   &lt;/listener&gt;
  
   &lt;filter&gt;
    &lt;filter-name&gt;Site_Filter&lt;/filter-name&gt;
    &lt;filter-class&gt;com.builders.support.center.ServletFilter&lt;/filter-class&gt;
   &lt;/filter&gt;
  
   &lt;filter-mapping&gt;
    &lt;filter-name&gt;Site_Filter&lt;/filter-name&gt;
    &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
   &lt;/filter-mapping&gt;
  
   &lt;servlet&gt;
    &lt;servlet-name&gt;supportCenter&lt;/servlet-name&gt;
    &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;
    &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
   &lt;/servlet&gt;
   &lt;servlet&gt;
    &lt;description&gt;Monitor servlet&lt;/description&gt;
    &lt;display-name&gt;Monitor servlet&lt;/display-name&gt;
    &lt;servlet-name&gt;Monitor&lt;/servlet-name&gt;
    &lt;servlet-class&gt;com.builders.support.center.Monitor&lt;/servlet-class&gt;
    &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
   &lt;/servlet&gt;
  
   &lt;servlet-mapping&gt;
    &lt;servlet-name&gt;supportCenter&lt;/servlet-name&gt;
    &lt;url-pattern&gt;*.html&lt;/url-pattern&gt;
   &lt;/servlet-mapping&gt;
  &lt;!--  
   &lt;servlet-mapping&gt;
    &lt;servlet-name&gt;supportCenter&lt;/servlet-name&gt;
    &lt;url-pattern&gt;/login&lt;/url-pattern&gt;
   &lt;/servlet-mapping&gt;
   &lt;servlet-mapping&gt;
    &lt;servlet-name&gt;supportCenter&lt;/servlet-name&gt;
    &lt;url-pattern&gt;/newlogin&lt;/url-pattern&gt;
   &lt;/servlet-mapping&gt;
   --&gt;
   &lt;servlet-mapping&gt;
    &lt;servlet-name&gt;Monitor&lt;/servlet-name&gt;
    &lt;url-pattern&gt;/servlet/Monitor&lt;/url-pattern&gt;
   &lt;/servlet-mapping&gt;
  
   &lt;session-config&gt;
    &lt;session-timeout&gt;360&lt;/session-timeout&gt;
   &lt;/session-config&gt;
   &lt;welcome-file-list&gt;
    &lt;welcome-file&gt;index.jsp&lt;/welcome-file&gt;
   &lt;/welcome-file-list&gt;
   &lt;error-page&gt;
    &lt;error-code&gt;400&lt;/error-code&gt;
    &lt;location&gt;/404error.jsp&lt;/location&gt;
   &lt;/error-page&gt;
   &lt;error-page&gt;
    &lt;error-code&gt;403&lt;/error-code&gt;
    &lt;location&gt;/WEB-INF/jsp/exceptions/accessError.jsp&lt;/location&gt;
   &lt;/error-page&gt;
   &lt;error-page&gt;
    &lt;error-code&gt;404&lt;/error-code&gt;
    &lt;location&gt;/404error.jsp&lt;/location&gt;
   &lt;/error-page&gt;
   &lt;error-page&gt;
    &lt;error-code&gt;408&lt;/error-code&gt;
    &lt;location&gt;/404error.jsp&lt;/location&gt;
   &lt;/error-page&gt;
   &lt;error-page&gt;
    &lt;error-code&gt;500&lt;/error-code&gt;
    &lt;location&gt;/404error.jsp&lt;/location&gt;
   &lt;/error-page&gt;
  </code></pre>
  
  <p>And my supportCenter-servlet.xml looks like this :</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  
      &lt;!--
          - Application context definition for "SupportCenter" DispatcherServlet.
      --&gt;
  
  &lt;beans  xmlns="http://www.springframework.org/schema/beans" 
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xmlns:p="http://www.springframework.org/schema/p" 
          xmlns:context="http://www.springframework.org/schema/context"
          xsi:schemaLocation="
          http://www.springframework.org/schema/beans 
          http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
          http://www.springframework.org/schema/context 
          http://www.springframework.org/schema/context/spring-context-2.5.xsd"&gt;
  
      &lt;context:component-scan base-package="com.builders.support.center.weblayer.springmvc.controllers"/&gt;
  
      &lt;bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"/&gt;
  
      &lt;bean id="supportCenterPropertyConfigurer"
            class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"&gt;
          &lt;property name="location"&gt;
              &lt;value&gt;/WEB-INF/properties/web-site.properties&lt;/value&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  
      &lt;bean id="viewResolver"
            class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
          &lt;property name="viewClass"&gt;
              &lt;value&gt;org.springframework.web.servlet.view.JstlView&lt;/value&gt;
          &lt;/property&gt;
          &lt;property name="prefix"&gt;
              &lt;value&gt;/WEB-INF/jsp/&lt;/value&gt;
          &lt;/property&gt;
          &lt;property name="suffix"&gt;
              &lt;value&gt;.jsp&lt;/value&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  
      &lt;bean id="urlMapping"
            class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"&gt;
          &lt;property name="mappings"&gt;
              &lt;props&gt;
                  &lt;prop key="/main.html"&gt;mainFormController&lt;/prop&gt;
  
                  &lt;prop key="/login"&gt;mainFormController&lt;/prop&gt;
                  &lt;prop key="/newlogin"&gt;mainFormController&lt;/prop&gt;
                  &lt;prop key="/fail_login.html"&gt;failLoginViewController&lt;/prop&gt;
                  &lt;prop key="/login.html"&gt;loginFormController&lt;/prop&gt;
                ...
  
      &lt;bean id="mainFormController"
            class="com.builders.support.center.weblayer.springmvc.controllers.MainFormController"&gt;
          &lt;property name="sessionForm"&gt;
              &lt;value&gt;true&lt;/value&gt;
          &lt;/property&gt;
          &lt;property name="commandName"&gt;
              &lt;value&gt;commandBean&lt;/value&gt;
          &lt;/property&gt;
          &lt;property name="commandClass"&gt;
              &lt;value&gt;com.builders.support.center.weblayer.springmvc.command.beans.MainCommandBean&lt;/value&gt;
          &lt;/property&gt;
          &lt;property name="formView"&gt;
              &lt;value&gt;main&lt;/value&gt;
          &lt;/property&gt;
          &lt;property name="successView"&gt;
              &lt;value&gt;main.html&lt;/value&gt;
          &lt;/property&gt;
          &lt;property name="bindOnNewForm"&gt;
              &lt;value&gt;true&lt;/value&gt;
          &lt;/property&gt;
     ...
  </code></pre>
  
  <p>Edit :</p>
  
  <p>Here are the URLs, only the 3rd one works correctly, got intercepted, all others didn't get intercepted and showed a login screen.</p>
  
  <p><img src="https://i.stack.imgur.com/fRdRF.png" alt="enter image description here"></p>