Spring Mapping Static MVC Resources

I have the following servlet mapping -

<!-- Mapping Static Resources --> <mvc:resources mapping="/css/**" location="/resources/css/" /> <mvc:resources mapping="/js/**" location="/resources/js/" /> <mvc:resources mapping="/images/**" location="/resources/images/" /> 

My link to the image in html is "/images/folder/imageName.jpg" - these images get me 404, whereas if I change the link to "/images/imageName.jpg" and transfer the image directly under the image folder, it gives me picture.

Do I need to somehow change the display of the servlet to take into account the hierarchical structure?

+4
source share
1 answer

You need to change image links. When you write

 <mvc:resources mapping="/images/**" location="/resources/images/" /> 

Then, your HTTP requests to /resources/images transferred to the webapp/images folder on the server. So in html you should have something like this:

 <img src="<spring:url value='/resources/images/logo.png'/>" 
+2
source

All Articles