Reputation: 2311
I have created a simple jsp page in the spring mvc project. But i am unable to load the images from the image folder. I tried with Real path and Context path still I am unable to load the images in to the jsp file.
Real path:
<%
String realPath = application.getRealPath("/");
%>
<img src="<%=realPath%>images\logo.png" alt="student" title="student">
Context Path:
<%
String contextPath = request.getContextPath();
%>
<img src="<%=realPath%>images\logo.png" alt="student" title="student">
My project folder struture looks like
Did I miss something? Do I need to make any configurations in the web.xml?
Any suggestions?
Upvotes: 0
Views: 2553
Reputation: 159096
\
, because URLs must use /
./
. Quoting javadoc of getContextPath()
:
The path starts with a "/" character but does not end with a "/" character.
This is how to do it:
<img src="${pageContext.request.contextPath}/images/logo.png" alt="student" title="student">
Upvotes: 1
Reputation: 630
You must configure your static resources like images, js and css files like that:
<mvc:resources mapping="/images/**" location="/images/"/>
In the above example, any requests from this url pattern /images/**, Spring will look for the resources from the /images folder.
Upvotes: 1