chonglawr chonglawr - 5 months ago 105
Java Question

How can I load an image from my resources/images folder in spring mvc?

I am trying to load 2 images from my resources/images folder and display them on my index.jsp:

<img src="<c:url value='/resources/images/harry_potter.jpg'/>"/>
<img alt="Image" src="${pageContext.request.contextPath}/resources/images/harry_potter.jpg">

<img src="<c:url value='/resources/images/hp.jpg'/>"/>
<img alt="Image" src="${pageContext.request.contextPath}/resources/images/hp.jpg">

When I load the page images don't appear, instead there are image icons. As you've seen in my index.jsp, I've tried 2 different methods for loading an image

I have an application.xml page and a dispatcher-servlet page.xml

In each file I have tried putting this under the context:component-scan

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

but I still do not see my images on the index page. Does anyone know why this isn't showing

My File Structure for reference:

File Image View

File Image View

In my web.xml for reference:



Console for reference

Console Image View

Console Image View


Try this please, may work;)


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


<mvc:resources mapping="/resources/**" location="/WEB-INF/resources/" />