title: How to redirect any url that do not match any @RequestMapping parameter in the application
body: <p>I use Spring MVC in my web application. I am trying to redirect any url that match the pattern <code>http://localhost:8080/my-app/*</code> to a specific controller. But if the url is something like the following, <code>http://localhost:8080/my-app/test</code> and if there is a controller as follows:</p>
  
  <p>@Controller
      @RequestMapping("test")
      public class TestClass
      {</p>
  
  <pre><code>    @RequestMapping(value = "/landing", method = RequestMethod.GET)
      public String selectHomePage(ModelMap model)
          {
          //do something
          }
  
  
      @RequestMapping(value = "/list", method = RequestMethod.GET)
      public String listFaqCollections(@ModelAttribute("ownedby") String ownedBy, ModelMap model)
      {
      //do something
      }
  }
  </code></pre>
  
  <p>And I have another class as follows:</p>
  
  <pre><code>@Controller
      public class InvalidUrslRedirect
      {
      @RequestMapping(method = RequestMethod.GET) 
      public String redirectInvalidUrls(Model model)
      { 
          //do something 
      }
  </code></pre>
  
  <p>All the urls that are invalid will be redirected to the above controller class.</p>
  
  <p>The valid urls would be as follows:</p>
  
  <pre><code>http://localhost:8080/my-app/test/landing
  http://localhost:8080/my-app/test/list?ownedby=me
  </code></pre>
  
  <p>But if the url is something like:</p>
  
  <pre><code>http://localhost:8080/my-app/test/list?ownedbys=me
  </code></pre>
  
  <p>the normal tomcat 404  error page is displayed and the it is not getting redirected to the <code>InvalidUrslRedirect</code> class</p>
  
  <p>In my <code>web.xml</code> file, I have the following:</p>
  
  <pre><code>&lt;listener&gt;
          &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt;
      &lt;/listener&gt;
  
      &lt;context-param&gt;
          &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
          &lt;param-value&gt;classpath:spring/core/root-context.xml, classpath:spring/core/spring-security.xml&lt;/param-value&gt;
      &lt;/context-param&gt;
      &lt;listener&gt;
      &lt;listener-class&gt;
          org.springframework.web.context.request.RequestContextListener
      &lt;/listener-class&gt;
      &lt;/listener&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>In the <code>spring-security.xml</code>, I have:</p>
  
  <pre><code>&lt;http auto-config="true" use-expressions="true"&gt;
  &lt;intercept-url pattern="/**" access="isFullyAuthenticated()"/&gt;
  </code></pre>
  
  <p>I have been searching the net for some time now, but could not find much help. is there any way i can achieve such a functionality. Thanks in advance</p>