Reputation: 25
I am using spring tool suite. I have placed the image file in folder WebContent/WEB-INF/resources
<img src="WebContent/WEB-INF/resources/team_pic1.jpg" alt="Mountain View" style="width:304px;height:228px;">
This is my servlet.xml code
<mvc:resources mapping="/resources/" location="/resources/" />
I am getting error as
Failed to load resource: the server responded with a status of 404 (Not Found) at http://localhost:8080/SpringMVCTest/WebContent/WEB-INF/resources/team_pic1.jpg
Here is my directory structure
PLS let me know where I am going wrong
here is the error I get when I run through browser
Upvotes: 2
Views: 1375
Reputation: 120771
Just try:
<c:url var="imgUrl" value="/resources/team_pic1.jpg" />
<img src="${imgUrl}" alt="Mountain View" style="width:304px;height:228px;">
this build the right URL to hit the resource handler.
You also have to correct the resource mapping:
/**
./WEB-INF/resources/
is the folder where your resources exist in the war!So I think this it the resource configuration you need:
<resources mapping="/resources/**" location="/WEB-INF/resources/" />
Upvotes: 1
Reputation: 5676
Content is (usually) served from WEB-INF
, so it is not part of the path.
Your configuration defines the mapping
<mvc:resources mapping="/resources/" location="/resources/" />
which says nothing more, that static resources are served from /resources
, which means, they are delivered as is.
You could use ${pageContext.request.contextPath}
- explanation here
<img src="${pageContext.request.contextPath}/resources/team_pic1.jpg" alt="Mountain View" style="width:304px;height:228px;">
Upvotes: 1