File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes JSP page not displaying the image Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "JSP page not displaying the image" Watch "JSP page not displaying the image" New topic

JSP page not displaying the image

tarun bansal

Joined: Mar 21, 2006
Posts: 11

I had a simple JSP file, the code for which is as follows

I had put the image file in the images sub directory under my app directory.
Even then the JSP page is not showing the image
mohit bahl
Ranch Hand

Joined: Mar 22, 2006
Posts: 48
Hi tarun

This can sometimes happen when using relative paths.

you can try giving the absolute path/ path from root


to err is human, but the company policy doesn't allow it!
Chetan Parekh
Ranch Hand

Joined: Sep 16, 2004
Posts: 3640
Originally posted by tarun bansal:

I had a simple JSP file, the code for which is as follows

Try with <img src="./images/tarun.jsp">.

My blood is tested +ve for Java.
Stefan Evans

Joined: Jul 06, 2005
Posts: 1518
or probably better

<img src="<%= request.getContextPath() %>/images/tarun.jpg">
<img src='<%= request.getContextPath() + "/images/tarun.jpg" %>'>

or in a jsp2.0 container using EL:
<img src="${pageContext.request.contextPath}/images/tarun.jpg"/>


Edit: Fixing code (thanks Bear)
- Leading slashes removed.
- changed EL expression from {$request.contextPath} to ${pageContext.request.contextPath}
[ June 07, 2006: Message edited by: Stefan Evans ]
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63533

Originally posted by Stefan Evans:
or probably better

No "probably" about it. Server-relative references are the best way to ensure that you get what you mean, and removes any artificial coupling between resources cause by page-relative addressing.

or in a jsp2.0 container using EL:
<img src="/${request.contextPath}/images/tarun.jpg"/>

Small correction -- should be:

No leading slash, and "request" is not a builtin scoped variable. You need to obtain the request from the pageContext.
[ June 01, 2006: Message edited by: Bear Bibeault ]

[Asking smart questions] [About Bear] [Books by Bear]
Richard Green
Ranch Hand

Joined: Aug 25, 2005
Posts: 536
Here's a tip:

Install the Web Developer plugin for FireFox browser. Then navigate to your jsp page using FireFox. In the Web Developer toolbar, select "Images > Find Broken Images".

This will show you exactly what image (full path) is broken. ie.,


Hope this helps

MCSD, SCJP, SCWCD, SCBCD, SCJD (in progress - URLybird 1.2.1)
I agree. Here's the link:
subject: JSP page not displaying the image
It's not a secret anymore!