Hyun Jung
Hyun Jung

Reputation: 69

JSP image couldn't be loaded

I have tried to put absolute path in jsp tag. But it doesn't display the image.

<div class="container">
    <img src="<c:url value='${pageContext.request.contextPath}/images/default-
    user-image.png'/>" alt="userImage" />
</div>

enter image description here

Upvotes: 0

Views: 177

Answers (1)

Gurkan Yesilyurt
Gurkan Yesilyurt

Reputation: 2675

JSTL <c:url> tag has the context attribute ( optional) and it is set the current application as the context by default.

So, you can use like this without contextPath:

<c:url value='/images/default-user-image.png'/>

Secondly, To serve static resources with Spring, check your static handlers whether it works correctly or not.

For your example, add the following mapping in XML might work.

<mvc:resources mapping="/images/**" location="/images/" />

Upvotes: 2

Related Questions