1

I have the following folder structure. I added mvc annotation and resources path but when I try call the resources in home.jsp like <img src= "/resources/images/spitter_avatar.png" />, it can't find anything.

Folder structure:

enter image description here

Here is my code in my servlet-config.xml file for resources:

<mvc:annotation-driven/>
<mvc:resources mapping="/resources/**" location="/resources/" />
SerhatCan
  • 590
  • 1
  • 7
  • 26

3 Answers3

6
<img src= "resources/images/spitter_avatar.png" /> 

try above remove "/" before resources

Pravin
  • 1,137
  • 12
  • 20
  • thank you it works. But what should I change to use it like `/resources` in jsp file. – SerhatCan Jul 16 '14 at 08:03
  • you have to add project name before /resources in your case its Spring3MVC so ie `src="/Spring3MVC/resources/images/spitter_avatar.png"` – Pravin Jul 16 '14 at 08:06
  • something like that `` does not work. I need to use it `` like that in jsp file – SerhatCan Jul 16 '14 at 08:11
  • 1
    @SerhatC See [this question](http://stackoverflow.com/questions/125359/any-clever-ways-of-handling-the-context-in-a-web-app) for some solutions to this problem. – Alexey Jul 16 '14 at 08:12
  • Ok thanks :) I'll look into it a little bit more later but it is a good post. – SerhatCan Jul 16 '14 at 08:18
  • I forgot to accept this answer before, thank you for your response :) – SerhatCan Sep 18 '15 at 12:21
1

if you wanted to start with / , then use JSTL C tag

<img src= "<c:url value="/resources/images/spitter_avatar.png"></c:url>" /> 
Oomph Fortuity
  • 5,710
  • 10
  • 44
  • 89
0
  1. The resources folder must be located inside the WebContent folder.
  2. Place ${pageContext.request.contextPath} before your items url on the jsp page. Example:
${pageContext.request.contextPath}/resources/images/springlogo.svg
RiveN
  • 2,595
  • 11
  • 13
  • 26