3

I have this image in my header template <img src="images/slide-1.jpg" alt="Slide #1" width="175" height="77" />

When the template is used from a gsp file inside the 'main' directory, the image is loaded. Although, if I have the same template being used inside a gsp file inside a controller, the image is not loaded. I have tried to change this:

<img src="images/slide-1.jpg" alt="Slide #1" width="175" height="77" />

to this:

<img src="../images/slide-1.jpg" alt="Slide #1" width="175" height="77" />

and it works, but now the image in the other page don't. Any idea to solve the problem? I know the key must be absolute path. But i've done some searches and found nothing.

Dan D.
  • 73,243
  • 15
  • 104
  • 123
John
  • 259
  • 8
  • 19

2 Answers2

6

You can put your images in resource folder (for example, in YOUR_PROJECT/web-app/images) then access it in gsp by resource tag. By this way you won't have the absolute path problem.

For a concrete example, you can refer this question.

Community
  • 1
  • 1
Hoàng Long
  • 10,746
  • 20
  • 75
  • 124
2

Try "${application.contextPath}/images/slide-1.jpg". It's a semi-absolute path that will work in any of your deployment environments.

Jordan H.
  • 331
  • 1
  • 3