user1755645
user1755645

Reputation: 945

Spring MVC Static Resource Mapping

I have the following servlet mapping present -

  <!--  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 image link in the html is "/images/folder/imageName.jpg" - These images get me a 404 whereas if the change the link to "/images/imageName.jpg" and move the image to directly under the images folder it gets me the image.

Do I need to modify my servlet mapping in any way to take into account the hierarchical structure?

Upvotes: 4

Views: 9011

Answers (1)

madhead
madhead

Reputation: 33501

You need to modify links to the images. When you write

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

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

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

Upvotes: 3

Related Questions