title: How do I map Spring MVC controller to a uri with and without trailing slash?
body: <p>I have a Spring Controller with several RequestMappings for different URIs. My servlet is "ui". The servlet's base URI only works with a trailing slash. I would like my users to not have to enter the trailing slash.</p>
  
  <p>This URI works:</p>
  
  <pre><code>http://localhost/myapp/ui/
  </code></pre>
  
  <p>This one does not:</p>
  
  <pre><code>http://localhost/myapp/ui
  </code></pre>
  
  <p>It gives me a HTTP Status 404 message.</p>
  
  <p>The servlet and mapping from my web.xml are:</p>
  
  <pre><code>&lt;servlet&gt;
      &lt;servlet-name&gt;ui&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;ui&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/ui/*&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;    
  </code></pre>
  
  <p>My Controller: </p>
  
  <pre><code>@Controller
  public class UiRootController {
  
      @RequestMapping(value={"","/"})
      public ModelAndView mainPage() { 
          DataModel model = initModel();
          model.setView("intro");     
          return new ModelAndView("main", "model", model);
      }
  
      @RequestMapping(value={"/other"})
      public ModelAndView otherPage() { 
          DataModel model = initModel();
          model.setView("otherPage");     
          return new ModelAndView("other", "model", model);
      }
  
  }
  </code></pre>