1

I have been trying to display an image in my JSP file but can't seem to it right. The picture is inside a folder named "img" which is in the same directory as my WEB-INF folder.

Inside my JSP I am trying to show the logo using normal HTML way of finding image but I can't seem to get it right. This is what I have for trying to display it. What I don't get it is when I am in Dreamweaver I see the image displayed but after deploying I no longer there. I have a structure like servlet (which is root folder and name of my WAR file) and the img and WEB-INF folder are under it.

Folders follow the hierarchy below:

servlet 
---->img
     --->psyberAssess.png
---->WEB-INF


This is the code from JSP that is not working:

<img src="img/psyberAssess.png" width="450" height="100" border="0" /><br>
informatik01
  • 16,038
  • 10
  • 74
  • 104
Raymond Nakampe
  • 371
  • 7
  • 22
  • 2
    Add context path to your image url. – seenukarthi May 18 '13 at 19:02
  • Hi KarthiKeyan, thanks for your response, so if I do get you correct what you mean is I should have a path of this sort ${servlet.contextPath}/img/psyberAssess.png where servlet is the name of my war file ? – Raymond Nakampe May 18 '13 at 19:22
  • It doesn't work, I tried using a jsp scriptlet like the following but still the pic won't appear PsybersgateLogo – Raymond Nakampe May 18 '13 at 20:20
  • 1
    Hi @Raymond Nakampe I checked the `<%=request.getContextPath()%>/img/psyberAssess.png` it is working for me. Please clear the cache of your browser and check. – seenukarthi May 19 '13 at 05:27
  • For some odd reason it continues to not display for mine when I use that even after clearing the cache. Out of interest how did you structure your folders ? i.e in which location did you place your img file ? – Raymond Nakampe May 19 '13 at 07:30
  • Hi I uploaded my sample in [github](https://github.com/seenukarthi/testweb) clone and run it using `mvn tomcat:run` – seenukarthi May 19 '13 at 09:08

3 Answers3

1

just add the img folder in WEB-INF folder instead of other folder.

Mehul Kaklotar
  • 365
  • 1
  • 19
0

Images and other resources must be outside the WEB-INF folder, they should be organized in folders in the root path of your web application. This is because the WEB-INF folder and its contents can be accessed only from the application server.

In short, your project should have this structure (the names are just a reference, you can name it as you want/prefer)

Project Name
- webapp
  - resources
    - images
    - js
    - css
  - WEB-INF
    - lib (libraries used on the project go here ALWAYS)
Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332
  • Hi Luiggi, Thanks for your response, I don't have it in the WEB-INF folder but they are in the root folder with WEB-INF i.e I have a structure like servlet(which is root folder and name of my war file) and the img and WEB-INF folder are under it. – Raymond Nakampe May 18 '13 at 19:16
  • @RaymondNakampe please edit your question and add the relevant content there. – Luiggi Mendoza May 18 '13 at 19:17
0

Try this with JSTL tag:

<img src="<c:url value="/img/psyberAssess.png"/>" width="450" height="100" border="0" />
Alex
  • 11,451
  • 6
  • 37
  • 52