title: Spring mvc is returning home page after two or more forward slashes
body: <p>I am learning/developing website in JSP with Sping MVC. The problem now I am facing is that when I try to visit url "localhost/site/about///" it shows default home page, if I go to "localhost/site" it shows home page and if I go to "localhost/about" it shows about page. So I don't know how to throw error page if someone tries to access page with any single forward slash. I mean if I try to access "localhost/site/about/" or "localhost/site/about///" I want my app to throw 404 error page.</p>
  
  <p>Here is my web.xml code</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"&gt;
    &lt;display-name&gt;Test&lt;/display-name&gt;
  
    &lt;servlet&gt;
      &lt;servlet-name&gt;dispatcher&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-mapping&gt;
      &lt;servlet-name&gt;dispatcher&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;
  
  &lt;/web-app&gt;
  </code></pre>
  
  <p>My dispatcher-servlet.xml file's codes are</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
         xmlns:context="http://www.springframework.org/schema/context"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns:mvc="http://www.springframework.org/schema/mvc"
         xsi:schemaLocation="
                   http://www.springframework.org/schema/beans
                   http://www.springframework.org/schema/beans/spring-beans.xsd
                   http://www.springframework.org/schema/context
                   http://www.springframework.org/schema/context/spring-context.xsd
                   http://www.springframework.org/schema/mvc
                   http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"&gt;
  
      &lt;context:component-scan base-package="com.test.router" /&gt;
      &lt;mvc:annotation-driven /&gt;
  
      &lt;bean id="viewResolver"
              class="org.springframework.web.servlet.view.InternalResourceViewResolver" &gt;
              &lt;property name="prefix"&gt;
                  &lt;value&gt;/WEB-INF/jsps/&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;/beans&gt;
  </code></pre>
  
  <p>My router file's codes are</p>
  
  <pre><code>package com.test.router;
  
  import org.springframework.stereotype.Controller;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.bind.annotation.RequestMethod;
  import org.springframework.web.servlet.ModelAndView;
  
  
  
  @Controller
  public class Router {
  
      @RequestMapping(value = "/", method = RequestMethod.GET)
      public ModelAndView homePage(){
  
          ModelAndView model = new ModelAndView("HomePage");
  
          model.addObject("title", "Welcome to home page");
          model.addObject("msg", "This is the home page.");
  
          return model;
  
      }
  
      @RequestMapping(value = "/about", method = RequestMethod.GET)
      public ModelAndView aboutPage(){
  
          ModelAndView model = new ModelAndView("AboutPage");
  
          model.addObject("title", "About Test website.");
  
          return model;
  
      }
  
      @RequestMapping(value = "/accounts/login", method = RequestMethod.GET)
      public ModelAndView loginPage(){
  
          ModelAndView model = new ModelAndView("accounts");
  
          model.addObject("title", "Login here to access Test Website.");
          model.addObject("pageTitle", "Login page.");
  
          return model;
  
      }
  
      @RequestMapping(value = "/accounts/signup", method = RequestMethod.GET)
      public ModelAndView signupPage(){
  
          ModelAndView model = new ModelAndView("accounts");
  
          model.addObject("title", "Signup here to join and explore Test Website.");
          model.addObject("pageTitle", "Signup page.");
  
          return model;
  
      }
  
  
      @RequestMapping(value = "/accounts/logout", method = RequestMethod.GET)
      public ModelAndView logoutPage(){
  
          ModelAndView model = new ModelAndView("accounts");
  
          model.addObject("title", "Logging you out securely.");
          model.addObject("pageTitle", "Logout page.");
  
          return model;
  
      }
  
  
  }
  </code></pre>
  
  <p>So can anyone tell me how can I stop showing default home page after single or multiple forward slashes? Thank you for help.</p>