Reputation: 3189
I have the following navigation links
<li><a href="account">My Account</a></li>
<li><a href="ewallet/register">Register E-Wallet</a></li>
Both links refer to a page template which contains an img
element as follows
<img src="resources/images/tdyslogo.png" alt="logo" width="150px" border="0">
The issues:
/business/ewallet/resources/images/tdyslogo.png
thus image not loaded/business/ewallet/account
hence I get 404
upon clickingI tried to change my mvc:resources to <mvc:resources mapping="/resources/**" location="resources/" />
in order to map any URL containing resources
to the correct resources folder but no avail.
Based on Absolute vs relative URLs it seems like I need to use relative or absolute URL correctly. If this is correct, how can I fix it ?
Upvotes: 0
Views: 227
Reputation: 46871
If you are using tomcat server then try with default servlet to serve static resoruces directly.
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>/resources/*</url-pattern>
</servlet-mapping>
Better use c:url
and use prefix /
in the value to make the url relative the context path.
<img id="logo" src="<c:url value='/resources/images/logo.png'/>" />
Dynamic project structure:
WebContent
|
|__resources
| |
| |__images
| |
| |__logo.png
|
|__WEB-INF
|
|__web.xml
Upvotes: 1
Reputation: 47300
You would conventionally have all the images in a static resources that is under the root, so
<img src="<c:url value='/resources/images/tdyslogo.png'/>" alt="logo" width="150px" border="0">
Should work, using jsp c tag, which is included like below :
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
Upvotes: 1