title: How to use "css" in the "jsp" in Spring MVC project?
body: <p>I am working on a spring MVC project in which I am trying to use <code>css</code> style sheets by referencing it to design my JSP page. But somehow my css files are not being picked up once I hit my method in the controller..</p>
  
  <p>Below is my JSP file -</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;link rel="stylesheet" type="text/css" href="test.css" /&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  
  &lt;h1&gt;All header 1 elements will be red&lt;/h1&gt;
  &lt;h2&gt;All header 2 elements will be blue&lt;/h2&gt;
  &lt;p&gt;All text in paragraphs will be green.&lt;/p&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>And below is my <code>test.css</code> file - </p>
  
  <pre><code>h1 {color:red;}
  h2 {color:blue;}
  p {color:green;}    
  </code></pre>
  
  <p>And below is my method in controller class -    </p>
  
  <pre><code>@RequestMapping(value = "testing", method = RequestMethod.GET)
  public Map&lt;String, String&gt; testing() {
  
      final Map&lt;String, String&gt; model = new LinkedHashMap&lt;String, String&gt;();
  
      return model;
  }
  </code></pre>
  
  <p>Directory structure is like this - </p>
  
  <pre>webapp/
  |-- resources/
  |   +-- css/
  |           test.css
  +- WEB-INF/
    +-- views/
          testing.jsp</pre>
  
  <p>But somehow it's not working for me.. Is there anything wrong I am doing here?          </p>
  
  <p><strong>UPDATE:-</strong></p>
  
  <p>Here is my web.xml file- </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"&gt;
    &lt;display-name&gt;testweb&lt;/display-name&gt;
    &lt;listener&gt;
      &lt;listener-class&gt;com.host.webres.resource.env.EbayResourceRuntimeListener&lt;/listener-class&gt;
    &lt;/listener&gt;
    &lt;welcome-file-list&gt;
      &lt;welcome-file&gt;index.html&lt;/welcome-file&gt;
      &lt;welcome-file&gt;index.htm&lt;/welcome-file&gt;
      &lt;welcome-file&gt;index.jsp&lt;/welcome-file&gt;
      &lt;welcome-file&gt;default.html&lt;/welcome-file&gt;
      &lt;welcome-file&gt;default.htm&lt;/welcome-file&gt;
      &lt;welcome-file&gt;default.jsp&lt;/welcome-file&gt;
      &lt;welcome-file&gt;index&lt;/welcome-file&gt;
    &lt;/welcome-file-list&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/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;/testweb/*&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <p>And below is my <code>context.xml</code> file -</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans:beans xmlns="http://www.springframework.org/schema/mvc"
      xmlns:mvc="http://www.springframework.org/schema/mvc"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:beans="http://www.springframework.org/schema/beans"
      xmlns:context="http://www.springframework.org/schema/context"
      xmlns:aop="http://www.springframework.org/schema/aop"
      xmlns:task="http://www.springframework.org/schema/task"
      xsi:schemaLocation="
          http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
          http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
          http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
          http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
          http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.1.xsd"&gt;
  
      &lt;!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure --&gt;
  
      &lt;!--  Allow proxys --&gt;
      &lt;aop:aspectj-autoproxy /&gt;
  
      &lt;!-- Enables the Spring MVC @Controller programming model --&gt;
      &lt;mvc:annotation-driven&gt;
              &lt;mvc:message-converters&gt;
                &lt;!--  Support AJAX processing with progressive rendering. Overrides HttpOutputMessage with RaptorResponseWriter --&gt;
              &lt;beans:bean class="com.host.terr.kernel.filter.RaptorJacksonHttpMessageConverter"/&gt;                 
              &lt;/mvc:message-converters&gt;
      &lt;/mvc:annotation-driven&gt;
  
      &lt;context:component-scan base-package="com.host.terr.config" /&gt;
      &lt;context:component-scan base-package="com.host.personalization.bullseye.zookeeper.p13nzook.controller" /&gt;       
  
      &lt;!-- Handles HTTP GET requests by efficiently serving up static resources 
           in the corresponding directory --&gt;
      &lt;resources mapping="/js/**" location="/js/" /&gt;
      &lt;resources mapping="/css/**" location="/css/" /&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/views/" /&gt;
          &lt;beans:property name="suffix" value=".jsp" /&gt;
      &lt;/beans:bean&gt;
  &lt;/beans:beans&gt;
  </code></pre>
  
  <p>This is exception I am getting on my console but browser shows the data without any css - </p>
  
  <pre><code>404 /testweb/test.css Not Found /testweb/test.css Not Found }, Correlations : {} }
  </code></pre>