title: How to map the servlet to a child route(like /blog)?
body: <p>I'm using SpringMVC and tomcat, and I want to assign all the URLs beginning with <code>/blog</code> to my servlet, here is my code.</p>
  
  <h3>web.xml</h3>
  
  <pre><code>&lt;web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
                               http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1"&gt;
  
      &lt;display-name&gt;Spring MVC XML Configuration Example&lt;/display-name&gt;
  
      &lt;context-param&gt;
          &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
          &lt;param-value&gt;classpath:app-config.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;servlet&gt;
          &lt;servlet-name&gt;my-dispatcher-servlet&lt;/servlet-name&gt;
          &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;
          &lt;init-param&gt;
              &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
              &lt;param-value&gt;classpath:web-config.xml&lt;/param-value&gt;
          &lt;/init-param&gt;
          &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
      &lt;/servlet&gt;
  
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;my-dispatcher-servlet&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/blog&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
  
  &lt;/web-app&gt;
  </code></pre>
  
  <h3>web-config.xml</h3>
  
  <pre><code>&lt;beans xmlns="http://www.springframework.org/schema/beans"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns:context="http://www.springframework.org/schema/context"
         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/mvc
                             http://www.springframework.org/schema/mvc/spring-mvc.xsd
                             http://www.springframework.org/schema/context
                             http://www.springframework.org/schema/context/spring-context.xsd "&gt;
  
      &lt;context:component-scan base-package="com.example" /&gt;
  
      &lt;mvc:annotation-driven /&gt;
      &lt;mvc:resources mapping="/blog/**" location="/WEB-INF/static/blog/" /&gt;
  
  &lt;/beans&gt;
  </code></pre>
  
  <h3>app-config.xml</h3>
  
  <pre><code>&lt;beans xmlns="http://www.springframework.org/schema/beans"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns:context="http://www.springframework.org/schema/context"
         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 "&gt;
  
      &lt;context:component-scan base-package="com.example" /&gt;
  
  &lt;/beans&gt;
  </code></pre>
  
  <p>It doesn't work. I got a 404 when trying to access <code>/blog/index.html</code>. However, it worked if I changed the <code>servlet-mapping</code> part in <code>web.xml</code> to the following one.</p>
  
  <pre><code>&lt;servlet-mapping&gt;
      &lt;servlet-name&gt;my-dispatcher-servlet&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/&lt;/url-pattern&gt; &lt;!-- from /blog to / --&gt;
  &lt;/servlet-mapping&gt;
  </code></pre>
  
  <p>But I don't want to do that, I only want the servlet to handle the URLs under <code>/blog</code>, can I do that? Should I change something in <code>web-config.xml</code> to make it work?</p>