0

I am relatively new to Java EE Spring Framework. I am running a spring mvc spring maven project in Netbeans and I have the following structure for the "Web Pages" directory in the project files:

-Web Pages
--WEB-INF
---views
----welcome.jsp
-resources
--DPI.PNG

and this is the configuration class:

public class HelloWorldConfiguration {

@Bean(name = "HelloWorld")
public ViewResolver viewResolver() {
    InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
    viewResolver.setViewClass(JstlView.class);
    viewResolver.setPrefix("/WEB-INF/views/");
    viewResolver.setSuffix(".jsp");

    return viewResolver;
}

public void addResourceHandlers(ResourceHandlerRegistry registry) {

    // Css resource.
    registry.addResourceHandler("/resources/**") //
            .addResourceLocations("/resources/");

}

}

and in the welcome.jsp I access the image using the following html:

<img src='/resources/DPI.PNG'>

and when I access the page it gives 404 not found for the image,

What is the problem??

m.y.m
  • 347
  • 4
  • 27
  • Note that `/resources/DPI.PNG` will point to `localhost/resources/DPI.PNG`. Unless you did some different setting, your application will have a context path. You need to consider the context path if you want to display the image. [Here](https://stackoverflow.com/questions/5066061/context-path-in-uris-of-static-resources-do-i-really-need-to-specify-it) you can find an example with JSTL. – BackSlash Aug 16 '17 at 15:21
  • To debug this, you can also try monitoring the network tab in chrome console and see what URL is being invoked for the URL. – SaAn Aug 16 '17 at 15:25

1 Answers1

-1

Try using jstl tag which includes the context path of the application.

<img src="<c:url value="/resources/DPI.PNG"/c:url>">
Monzurul Shimul
  • 8,132
  • 2
  • 28
  • 42