C0ZEN
C0ZEN

Reputation: 934

img is not displayed in JSP/TomCat

I've seen a lot of thread about the same problem. However all the solutions are not working for me. The problem is simple: my image is not displayed on my page, it is replace by the alt text.

Path of my image: WebContent/LIB/image/my-image.png
- This is not in the WEB-INF folder (good practice).
- I tried with another image (.jpg), but failed. I saw a lot of people explain that the real problem was the path. I tried all these path but any one was working:

<img src='<c:url value="/LIB/image/my-image.png"/>' alt="KO"/>
// http://localhost:8080/3JVA-Project-SupTrip/WebContent/LIB/image/%3Cc:url%20value=%22/LIB/image/my-image.png%22/%3E

<img src="LIB/image/my-image.png" alt="KO"/>
// http://localhost:8080/3JVA-Project-SupTrip/WebContent/LIB/image/LIB/image/my-image.png

<img src="/LIB/image/my-image.png" alt="KO"/>
// http://localhost:8080/LIB/image/my-image.png

<img src="../LIB/image/my-image.png" alt="KO"/>
// http://localhost:8080/3JVA-Project-SupTrip/WebContent/LIB/LIB/image/my-image.png

<img src="<%=request.getContextPath()%>/LIB/image/my-image.png" alt="KO"/>
// http://localhost:8080/3JVA-Project-SupTrip/LIB/image/my-image.png

<img src="<%=request.getContextPath()%>/WebContent/LIB/image/my-image.png" alt="KO"/>
// http://localhost:8080/3JVA-Project-SupTrip/WebContent/LIB/image/my-image.png

This is the logical URI for my image: http://localhost:8080/3JVA-Project-SupTrip/WebContent/LIB/image/my-image.png

I really need your help, thank you buddies.

EDIT: Add some comments with the URI (last one sounds perfect but not working)

For example, this include works:

<!-- Main CSS -->
<style type="text/css">
    <%@ include file="../LIB/css/main.css" %>
</style>

Structure:
-3JVA-Project-SupTrip
--build
--src
--WebContent
---LIB
----image
-----my-image.png
---META-INF
---WEB-INF

Upvotes: 0

Views: 4559

Answers (1)

Vishal Gajera
Vishal Gajera

Reputation: 4207

please use this path,

<img src="/LIB/image/my-image.png" alt="KO"/>

It should be work because in my case it works fine.

Also, if you feel free then change name from 'LIB' to 'assets'.

EDITED :

<input type="image" src="LIB/image/ttt.jpg"/>

EDITED REPEAT

<img src="LIB/image/bg.jpg" alt="Smiley face" height="42" width="42">

Kindly confirm it, it works in all cases.

Upvotes: 2

Related Questions