title: Spring controller mapping configuration and static resources
body: <p>I have an issue with intercepting request to static resources by controller.</p>
  
  <p>Here is web.xml (part related with the problem):</p>
  
  <pre><code>&lt;servlet&gt;
      &lt;servlet-name&gt;testing&lt;/servlet-name&gt;
      &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;
  &lt;/servlet&gt;
  &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;testing&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/testing/*&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  </code></pre>
  
  <p>Here is testing-servlet.xml:</p>
  
  <pre><code>&lt;mvc:annotation-driven /&gt;
  &lt;mvc:resources mapping="/resources/**" location="/WEB-INF/resources/" /&gt;
  
  &lt;bean id="jspViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
      &lt;property name="viewClass" value="org.springframework.web.servlet.view.JstlView" /&gt;
      &lt;property name="prefix" value="/WEB-INF/jsp/" /&gt;
      &lt;property name="suffix" value=".jsp" /&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>Here is controller class source code:</p>
  
  <pre><code>@Controller
  @RequestMapping(value = "/testing")
  public class TestingController {
      @RequestMapping(method = RequestMethod.GET)
      public String doSomething() {
          return "doView";
      }
  
      @RequestMapping(value = "/getSomething", method = RequestMethod.GET)
      public String getSomething(@RequestParam String id) {
          return "getView";
      }
  }
  </code></pre>
  
  <p>And the last snipet of doView.jsp and getView.jsp files with declaration of static file with JavaScript:</p>
  
  <pre><code>&lt;script src="testing/resources/js/jquery.js"&gt;&lt;/script&gt;
  </code></pre>
  
  <p>There is one thing I don't understand - why do I get doView.jsp by entering only <code>http://localhost:8080/app/testing</code> but in order to get getView.jsp I need to enter <code>http://localhost:8080/app/testing/testing/getSomething</code> ("testing" typed twice).</p>
  
  <p>And now the main reason of this topic - when I remove request mapping annotation from class definition (<code>@RequestMapping(value = "/testing")</code> and leave those on methods then I'm not able to get jquery.js file at all. When I type <code>http://localhost:8080/app/testing/resources/js/jquery.js</code> I get doView.jsp. There isn't any issue reported by developer tool in browser (missing jquery.js file or something) - this request is just intercepted by Spring's dispatcher servlet. The only advantage in this configuration is that I don't have to type "testing" twice in order to open getView.jsp. ;)</p>
  
  <p>Does anyone know solution how to make <code>mvc:resources</code> tag working in such situation? And no I can't set URL mapping of whole testing servlet to "/". ;)</p>