4

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?

2
  • This looks correct... have you checked in Firebug for the URLs the browser is using to fetch the images? There may be a relative path issue. Commented Jan 29, 2013 at 17:58
  • 2
    Could you give us the actual folder structure.From the mapping i understand /images is mapped to '/resources/images/' assuming the images are directly under /resources/images/ directory. So why would you access it "/images/folder/imageName.jpg" unless the image directory is '/resources/images/folder/' Commented Feb 3, 2013 at 7:04

1 Answer 1

3

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'/>"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.