title: How to use static resources in spring mvc?
body: <p>How to use static resources in spring mvc? I just want to insert some images in jsp. In which place I must locate my resources? Last time I used to add mvc:recources in servlet-context, but it shows me few errors with mapping. </p>
  
  <p>I'm still in trouble. I've made another question. Please, HALP.
  <a href="https://stackoverflow.com/questions/18020129/troubles-with-static-resources-and-mvcresources">https://stackoverflow.com/questions/18020129/troubles-with-static-resources-and-mvcresources</a></p>
  
  <p>My config:</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:aop="http://www.springframework.org/schema/aop"
      xmlns:beans="http://www.springframework.org/schema/beans"
      xmlns:context="http://www.springframework.org/schema/context"
      xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:jee="http://www.springframework.org/schema/jee"
      xmlns:lang="http://www.springframework.org/schema/lang" xmlns:p="http://www.springframework.org/schema/p"
      xmlns:tx="http://www.springframework.org/schema/tx" xmlns:util="http://www.springframework.org/schema/util"
      xsi:schemaLocation="
      http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
          http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
          http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
          http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
          http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd
          http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
          http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd"&gt;
  
  
  
      &lt;context:annotation-config /&gt;
      &lt;context:component-scan base-package="net.babobka.blog" /&gt;
  
  
      &lt;import resource="../../db/db-config.xml" /&gt;
  
  
  
      &lt;bean id="tilesConfigurer"
          class="org.springframework.web.servlet.view.tiles2.TilesConfigurer"&gt;
          &lt;property name="definitions"&gt;
              &lt;list&gt;
                  &lt;value&gt;/WEB-INF/tiles.xml&lt;/value&gt;
              &lt;/list&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  
      &lt;bean id="viewResolver"
          class="org.springframework.web.servlet.view.UrlBasedViewResolver"&gt;
          &lt;property name="viewClass"
              value="org.springframework.web.servlet.view.tiles2.TilesView" /&gt;
      &lt;/bean&gt;
  
  &lt;/beans&gt;
  </code></pre>
  
  <p>My jsp:</p>
  
  <pre><code>&lt;%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%&gt;
  &lt;%@taglib uri="http://www.springframework.org/tags" prefix="spring"%&gt;
  &lt;%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%&gt;
  &lt;%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%&gt;
  &lt;%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %&gt;
  &lt;strong&gt;&lt;h1&gt;
          &lt;a href="${pageContext.request.contextPath}"&gt;Blog&lt;/a&gt;
      &lt;/h1&gt;&lt;/strong&gt;
  &lt;p&gt;
      &lt;small&gt;With Spring MVC&lt;/small&gt;&lt;img src='&lt;c:url value="/static/img/logo.gif"/&gt;' /&gt;
  </code></pre>
  
  <p>And part of controller:</p>
  
  <pre><code>import org.springframework.stereotype.Controller;
  import net.babobka.blog.domain.Content;
  import net.babobka.blog.service.ContentService;
  import net.babobka.blog.domain.News;
  import net.babobka.blog.service.NewsService;
  import net.babobka.blog.domain.Tags;
  import net.babobka.blog.service.TagsService;
  import java.util.Map;
  import net.babobka.blog.form.SearchForm;
  
  import org.springframework.beans.factory.annotation.Autowired;
  
  import org.springframework.validation.BindingResult;
  import org.springframework.web.bind.annotation.ModelAttribute;
  import org.springframework.web.bind.annotation.PathVariable;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.bind.annotation.RequestMethod;
  
  @Controller
  public class HomeController {
  
      @Autowired
      private ContentService contentService;
      @Autowired
      private NewsService newsService;
      @Autowired
      private TagsService tagsService;
  
      long HM = 3;
  
      @RequestMapping(value = "/", method = RequestMethod.GET)
      public String listContacts(Map&lt;String, Object&gt; map,@ModelAttribute("search") SearchForm query, BindingResult result) {
          long nums = newsService.getNumRows();
          map.put("old", HM);
          map.put("news", new News());
          map.put("nums", nums);
          map.put("newsList", newsService.getSomeNews(0, HM));
  
          return "content";
      }
  
      @RequestMapping(value = "/about", method = RequestMethod.GET)
      public String getAboutPage(Map&lt;String, Object&gt; map,@ModelAttribute("search") SearchForm query, BindingResult result) {
  
          map.put("news", new News());
          map.put("newsList", newsService.getAboutPage());
  
          return "about";
      }
  </code></pre>
  
  <p>Web.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"&gt;
  
      &lt;!-- The definition of the Root Spring Container shared by all Servlets 
          and Filters --&gt;
      &lt;context-param&gt;
          &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
  
          &lt;param-value&gt;
          /WEB-INF/spring/root-context.xml
          /WEB-INF/spring/application-security.xml
          &lt;/param-value&gt;
      &lt;/context-param&gt;
  
  
  
      &lt;!-- Creates the Spring Container shared by all Servlets and Filters --&gt;
      &lt;listener&gt;
          &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt;
      &lt;/listener&gt;
  
  
  
      &lt;!-- Processes application requests --&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;
      &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;/web-app&gt;
  </code></pre>