title: Unable to load static resources in spring mvc application
body: <p>I am new to Spring MVC. I am creating a project which has an input form taking some details and then displaying them on another page. I have a controller class which has two request mapping methods. One goes to the input page and another to the display page. The application is working fine but I am unable to load static resources like css. My css is located under WebContent in a folder named css. Below is my project structure in eclipse</p>
  
  <p><a href="http://i.stack.imgur.com/74bM2.png" rel="nofollow">http://i.stack.imgur.com/74bM2.png</a></p>
  
  <p>I deployed the application in jboss. My context root is set as productCat</p>
  
  <p>Below is my web.xml</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_2_5.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;servlet&gt;
        &lt;servlet-name&gt;springmvc&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/config/springmvc-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;springmvc&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  </code></pre>
  
  <p></p>
  
  <p>And my springmvc-config.xml</p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="UTF-8"?&gt;
      &lt;beans xmlns="http://www.springframework.org/schema/beans"   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:mvc="http://www.springframework.org/schema/mvc" 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/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.kaushik.controller" /&gt;
  &lt;mvc:annotation-driven /&gt;
  &lt;mvc:resources location="/css/**" mapping="/css/"/&gt;
  &lt;bean id="viewResolver"
      class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
      &lt;property name="prefix" value="/WEB-INF/jsp/"&gt;&lt;/property&gt;
      &lt;property name="suffix" value=".jsp"&gt;&lt;/property&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p></p>
  
  <p>Below is my controller class</p>
  
  <pre><code>    package com.kaushik.controller;
  
      import org.apache.commons.logging.Log;
      import org.apache.commons.logging.LogFactory;
      import org.springframework.stereotype.Controller;
      import org.springframework.ui.Model;
      import org.springframework.web.bind.annotation.RequestMapping;
  
      import com.kaushik.domain.Product;
      import com.kaushik.form.ProductForm;
  
      @Controller
      public class ProductController
      {
         private static final Log logger = LogFactory.getLog(ProductController.class);
  
      @RequestMapping(value="/product_input.action")
      public String inputProduct()
      {
        logger.info("inputProduct called");
        return "ProductForm";
      }
  
      @RequestMapping(value="/product_save.action")
      public String saveProduct(ProductForm productForm, Model model)
      {
        logger.info("SaveProductController called");
        // create model
        Product product = new Product();
        product.setName(productForm.getName());
        product.setDescription(productForm.getDescription());
        try
        {
          product.setPrice(Float.parseFloat(productForm.getPrice()));
        }
        catch (NumberFormatException num)
        {
  
        }
        // TODO code to save product
        // store model in a variable for the view
        model.addAttribute("product",product);
        return "/ProductDetails";
       }
  
       }
  </code></pre>
  
  <p>Here is my ProductForm.jsp</p>
  
  <pre><code>    &lt;!DOCTYPE HTML&gt;
      &lt;html&gt;
      &lt;head&gt;
      &lt;title&gt;Add Product Form&lt;/title&gt;
      &lt;link href="css/main.css" rel="stylesheet" &gt;
  
      &lt;/head&gt;
      &lt;body&gt;
  
            &lt;div id="global"&gt;
                &lt;form action="product_save.action" method="post"&gt;
                  &lt;fieldset&gt;
                     &lt;legend&gt;Add a product&lt;/legend&gt;
                     &lt;p&gt;
                     &lt;label for="name"&gt;Product Name: &lt;/label&gt;
                     &lt;input type="text" id="name" name="name" 
                  tabindex="1"&gt;
                     &lt;/p&gt;
                     &lt;p&gt;
                     &lt;label for="description"&gt;Description: &lt;/label&gt;
                     &lt;input type="text" id="description" 
                  name="description" tabindex="2"&gt;
                     &lt;/p&gt;
                      &lt;p&gt;
                      &lt;label for="price"&gt;Price: &lt;/label&gt;
                      &lt;input type="text" id="price" name="price" 
                  tabindex="3"&gt;
                     &lt;/p&gt;
                     &lt;p id="buttons"&gt;
                     &lt;input id="reset" type="reset" tabindex="4"&gt;
                     &lt;input id="submit" type="submit" tabindex="5" 
                  value="Add Product"&gt;
                     &lt;/p&gt;
                  &lt;/fieldset&gt;
                &lt;/form&gt;
            &lt;/div&gt;
      &lt;body&gt;
      &lt;/html&gt;
  </code></pre>
  
  <p>As you can see I used  in my servlet xml but it is still not loading the css. The error in the browser is </p>
  
  <blockquote>
    <p>Failed to load resource: the server responded with a status of 404 (Not Found)</p>
  </blockquote>
  
  <p>The url that it is trying to access is <a href="http://localhost:8080/productCat/css/main.css" rel="nofollow">http://localhost:8080/productCat/css/main.css</a></p>