ishanbakshi
ishanbakshi

Reputation: 1965

what is the relative path to add image in jsp page in a spring MVC project

I am using spring mvc 3.2.0.RELEASE. I want to display an image in my jsp tag and for that i am using this line in my jsp code:

    <img src="images/login_pic.png"/>

it is not fetching the image. Can you please suggest a solution ?

My JSP is in the location : WebContent/WEB-INF/views/index.jsp

my image is in the location: WebContent/WEB-INF/views/images/login_pic.png

Upvotes: 0

Views: 10952

Answers (3)

Rafik BELDI
Rafik BELDI

Reputation: 4158

<mvc:resources mapping="/images/**" location="/WEB-INF/views/images/"
    cache-period="10000" />

add this to your context configuration file , then you can refer your images this way:

<img src="/images/login_pic.png"/>

Upvotes: 1

Ashish Ratan
Ashish Ratan

Reputation: 2870

Try this:

<img src="${pageContext.request.contextPath}/images/login_pic.png"/> 

Upvotes: 3

vico
vico

Reputation: 2142

 <img src="/images/login_pic.png"/>

this will go from the very top root (this one should do) given that your root is on the index.

 <img src="../images/login_pic.png"/>

this will go one level above your current location

 <img src="../../images/login_pic.png"/>

this will go two level above your current location

<img src="images/login_pic.png"/>

what you have looks at the same folder

/folder
  html
  login_pic.png

Upvotes: 0

Related Questions