title: Spring-MVC : Unable to access static files in the ressource folder
body: <p>I have a maven webapp running in a tomcat server, using spring-mvc 4 dependency.and i can't load <strong>login.css</strong> file located in a folder named <strong>css</strong> inside the resource folder of the app. the request returns a 404 file not found error.</p>
  
  <p>The URL being used to access the file is :
     <a href="http://localhost:8080/WFMConf/resources/css/login.css" rel="nofollow">http://localhost:8080/WFMConf/resources/css/login.css</a></p>
  
  <p>the css doesn't load when i access the JSP page directly either.</p>
  
  <p>here is the relevant code :</p>
  
  <p><strong>Web.xml :</strong></p>
  
  <pre><code>&lt;web-app&gt;
  
  
  &lt;display-name&gt;Archetype Created Web Application&lt;/display-name&gt;
  &lt;context-param&gt;
      &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
      &lt;param-value&gt;
              /WEB-INF/spring/spring-security.xml
              /WEB-INF/spring/spring-database.xml
      &lt;/param-value&gt;
  &lt;/context-param&gt;
  
  &lt;!-- Spring Security --&gt;
  &lt;filter&gt;
      &lt;filter-name&gt;springSecurityFilterChain&lt;/filter-name&gt;
      &lt;filter-class&gt;org.springframework.web.filter.DelegatingFilterProxy
      &lt;/filter-class&gt;
  &lt;/filter&gt;
  
  &lt;filter-mapping&gt;
      &lt;filter-name&gt;springSecurityFilterChain&lt;/filter-name&gt;
      &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
  &lt;/filter-mapping&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;appServlet&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;/WEB-INF/spring/appServlet/servlet-context.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;appServlet&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  </code></pre>
  
  <p></p>
  
  <p><strong>servlet-context.xml :</strong></p>
  
  <pre><code>&lt;!-- Enables the Spring MVC @Controller programming model --&gt;
  &lt;annotation-driven /&gt;
  
  &lt;!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory --&gt;
  &lt;resources mapping="/resources/**" location="/resources/" /&gt;
  
  &lt;!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory --&gt;
  &lt;beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
      &lt;beans:property name="prefix" value="/WEB-INF/vues/" /&gt;
      &lt;beans:property name="suffix" value=".jsp" /&gt;
  &lt;/beans:bean&gt;
  
  &lt;context:component-scan base-package="com.myApp.controllers" /&gt;
  
  
  &lt;/beans:beans&gt;
  </code></pre>
  
  <p><strong>spring-security.xml :</strong></p>
  
  <pre><code>&lt;http pattern="/resources/**" security="none" /&gt;
  &lt;http auto-config="true" use-expressions="true"&gt;
      &lt;access-denied-handler error-page="/403" /&gt;
      &lt;!--  &lt;intercept-url pattern="/admin**" access="hasRole('ADMIN')" /&gt; --&gt;
      &lt;form-login 
          login-page="/login" 
          default-target-url="/index" 
          authentication-failure-url="/login?error" 
          username-parameter="username"
          password-parameter="password" /&gt;
      &lt;logout logout-success-url="/login?logout" invalidate-session="true"/&gt;
      &lt;!--   enable csrf protection --&gt;
      &lt;csrf/&gt; 
  &lt;/http&gt;
  
  
  &lt;authentication-manager&gt;
    &lt;authentication-provider&gt;
      &lt;jdbc-user-service data-source-ref="dataSource"
        users-by-username-query=
          "select login,pwd, enabled from utilisateur where login=?"
        authorities-by-username-query=
          "select login, role from role where login =?" /&gt;
    &lt;/authentication-provider&gt;
  &lt;/authentication-manager&gt;
  </code></pre>
  
  <p><strong>login.jsp :</strong></p>
  
  <pre><code>&lt;%@ page language="java" contentType="text/html; charset=ISO-8859-1"
  pageEncoding="ISO-8859-1" isELIgnored="false"%&gt;
  &lt;%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;title&gt;Login Page&lt;/title&gt;
  &lt;link href="&lt;c:url value="/resources/css/login.css" /&gt;" rel="stylesheet"     type="text/css" /&gt;
  &lt;/head&gt;
  </code></pre>
  
  <p><strong>Edit :</strong></p>
  
  <p>the output link on the generated html is : 
  <code>&lt;link href="/WFMConf/resources/css/login.css" rel="stylesheet"&gt;</code></p>
  
  <p>the directory structure is the following :</p>
  
  <pre><code>-&gt;src
    -&gt;main
     -&gt;java
        -&gt;com.myapp.controllers.MainController
     -&gt;resources
        -&gt;JS
        -&gt;img
        -&gt;css
          -&gt;login.css
     -&gt;webapp
        -&gt;WEB-INF
          -&gt;spring
            -&gt;appServlet
              -&gt;servlet-context.xml
            -&gt;spring-database.xml
            -&gt;spring-security.xml
          -&gt;vues
            -&gt;login.jsp
          -&gt;web.xml
  </code></pre>