title: Spring MVC JSPs Cannot Locate Javascript or CSS
body: <p>This question seems to have been asked a few times, but after reviewing too many of them to count, I am still seeing this problem.</p>
  
  <p>The .jsp's in my Spring MVC project are unable to locate any .css or .js files even though they are in the war and the given file paths are correct.</p>
  
  <p>Depending on my configuration I see two errors. The first being:</p>
  
  <pre><code>WARNING: No mapping found for HTTP request with URI [/waypoint/css/bootstrap.min.css] in DispatcherServlet with name 'waypoint'
  </code></pre>
  
  <p>Note that my controller is being reached and I am seeing the page, just without any formatting or javascript.</p>
  
  <p>I see this error with the following configuration:</p>
  
  <p><strong>web.xml</strong></p>
  
  <pre><code>&lt;servlet-mapping&gt;
      &lt;servlet-name&gt;waypoint&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  </code></pre>
  
  <p><strong>waypoint-servlet.xml</strong>
          </p>
  
  <pre><code>&lt;bean id="viewResolver"
      class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
  
      &lt;property name="prefix"&gt;
          &lt;value&gt;/WEB-INF/pages/&lt;/value&gt;
      &lt;/property&gt;
      &lt;property name="suffix"&gt;
          &lt;value&gt;.jsp&lt;/value&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p><strong>File structure:</strong></p>
  
  <pre><code>WEB-INF
  | - css
  |   ` - all .css files
  | - js
  |   ` - you guessed it...
  | - pages
  |   ` - all .jsp files
  | - waypoint-servlet.xml
  ` - web.xml
  </code></pre>
  
  <p>I have read a lot of other posts that have resolved this issue using the <code>mvc:resource</code> tag. </p>
  
  <p>When I include the <code>mvc:resource</code> tag, I see 404 errors for my .jsp's. This occurs even when I change the servlet mapping to <code>/*</code>, <code>/**</code>, <code>/&lt;some-name&gt;/</code>, and <code>/&lt;some-name&gt;/*</code>.</p>
  
  <p>I have also tried moving the static files outside of the WEB-INF folder:</p>
  
  <pre><code>| - resources
  |  | - css
  |  |   ` css...
  |  | - js
  |      ` js...
  | - WEB-INF
  </code></pre>
  
  <p>As I mentioned, I tried many different mapping combinations for the <code>mvc:resource</code> tag, for both of the above file structures. Some examples include:</p>
  
  <pre><code>&lt;mvc:resources mapping="waypoint/resources/css/**" location="/resources/css/" /&gt;
  &lt;mvc:resources mapping="resources/css/**" location="/resources/css/" /&gt;
  &lt;mvc:resources mapping="css/**" location="/resources/css/" /&gt;
  &lt;mvc:resources mapping="css/**" location="WEB-INF/css/" /&gt;
  &lt;mvc:resources mapping="css/**" location="css/" /&gt;
  </code></pre>
  
  <p>I tried the above with combinations of the following on the .jsp side as well:</p>
  
  <pre><code>&lt;link href="classpath:/resources/css/bootstrap.min.css" rel="stylesheet" type="text/css"&gt;
  &lt;link href="../css/bootstrap.min.css" rel="stylesheet" type="text/css"&gt;
  &lt;link href="&lt;c:url value="../resources/css/bootstrap.min.css"/&gt;" rel="stylesheet" type="text/css" /&gt;
  &lt;link href="&lt;c:url value="../css/bootstrap.min.css"/&gt;" rel="stylesheet" type="text/css" /&gt;
  </code></pre>
  
  <p>Has anyone experienced this before that might be able to lend a hand? It would be greatly appreciated. If you need any other info please let me know.</p>
  
  <p>Thanks.</p>
  
  <p><strong>SOLUTION</strong></p>
  
  <p>I was able to resolve this issue by adding servlet mappings for *.css and *.js to the fefault servlet:</p>
  
  <pre><code>&lt;servlet-mapping&gt;
      &lt;servlet-name&gt;waypoint&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;default&lt;/servlet-name&gt;
      &lt;url-pattern&gt;*.css&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;default&lt;/servlet-name&gt;
      &lt;url-pattern&gt;*.js&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  </code></pre>
  
  <p>This required the removal of the <code>&lt;mvc:resource&gt;</code> tags. I also required the use of the <code>resource/css/</code> directory outside of the <code>WEB-INF</code> folder. I referenced the js and css files in the JSPs as follows:</p>
  
  <pre><code>&lt;link href="&lt;c:url value="/resources/css/bootstrap.min.css"/&gt;" rel="stylesheet" type="text/css" /&gt;
  </code></pre>
  
  <p>Thanks for reading!</p>