title: How to display an image with Spring MVC using JSP
body: <p>I'm having a hard time getting an image to display using Spring MVC with JSP.  I know there are other very similar SO questions, but none of the answers on those questions seemed to work.</p>
  
  <p>I have a very simple project with only two java files and a single JSP file to display.  This is my WebMvcConfigurerAdapter class:</p>
  
  <pre><code>@Configuration
  @ComponentScan(basePackages="com.rigatron.rigs4j")
  @EnableWebMvc
  public class MvcConfiguration extends WebMvcConfigurerAdapter{
  
  @Bean
  public ViewResolver getViewResolver(){
      InternalResourceViewResolver resolver = new InternalResourceViewResolver();
      resolver.setPrefix("/WEB-INF/views/");
      resolver.setSuffix(".jsp");
      return resolver;
  }
  
  @Override
  public void addResourceHandlers(ResourceHandlerRegistry registry) {
      registry.addResourceHandler("/resources/**")
              .addResourceLocations("/resources/");
  }
  </code></pre>
  
  <p>This is my home page's controller class:</p>
  
  <pre><code>@Controller
  public class HomeController {
  
  @RequestMapping(value="/")
  public ModelAndView test(HttpServletResponse response) throws IOException {
      return new ModelAndView("home");
  }
  </code></pre>
  
  <p>Here is the line in the JSP file where I am trying to display my image:</p>
  
  <pre><code>&lt;img src="/resources/old.jpeg" alt="Photo of Youthful William" id="pic" /&gt;
  </code></pre>
  
  <p>I have old.jpeg in my /resources/ folder.  The rest of the page is displayed fine, but only the alt text is displayed here.  </p>
  
  <p>I am deploying this app using Tomcat8, and I have this line is my Maven pom file which copies the produced WAR file into Tomcat's webapps directory every time I build it:</p>
  
  <pre><code>&lt;plugin&gt;
    &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
    &lt;artifactId&gt;maven-war-plugin&lt;/artifactId&gt;
    &lt;configuration&gt;
      &lt;outputDirectory&gt;C:\my\local\dir\tomcat8\webapps&lt;/outputDirectory&gt;
    &lt;/configuration&gt;
  &lt;/plugin&gt;
  </code></pre>
  
  <p>So when I navigate using my browser to localhost:8080/myprojectname the rest of the JSP file is displayed correctly, but the photo is not, only the alt text.  Any help with this issue would be appreciate.</p>