0

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:

  1. upon clicking the second link, the img element is resolving to wrong URL that is /business/ewallet/resources/images/tdyslogo.png thus image not loaded
  2. when I tried to access other navigation links, the URL also resolving to wrong url /business/ewallet/account hence I get 404 upon clicking

I 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 ?

Community
  • 1
  • 1
abiieez
  • 3,139
  • 14
  • 57
  • 110

2 Answers2

1

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" %>
NimChimpsky
  • 46,453
  • 60
  • 198
  • 311
1

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

Read more...

Community
  • 1
  • 1
Braj
  • 46,415
  • 5
  • 60
  • 76