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

images not showing

Patricia Murphy

Joined: Feb 22, 2006
Posts: 5

I created a HTML protype website and then copied these pages to JSP pages.
However, my images won't show when the JSP pages load.
Any idea how to fix this?

Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63838

Remeber that JSP is just a technology that creates HTML. So there's nothing special to do except to make sure that your image URLs are valid.

The most common cuase for such problems is page-relative URL s such as "../this.gif" and such.


What's the URL of your JSP page look like? And how are you formatting the URLs for the images?

[Asking smart questions] [About Bear] [Books by Bear]
Naveen Kumar
Ranch Hand

Joined: Dec 14, 2006
Posts: 35

If images are differnet directory and JSP is in different director.

add the below code in your jsp file.

String contextPath = request.getContextPath();

<img src="<%= contextPath %>/images/contact.gif" alt="News"></img>

Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63838

What kumar is saying is that it's best to use server-relative URLs, and he is correct.

However, if you are using JSP 2.0 you should not be including scriptlet expressions in your pages. The correct JSP 2.0 syntax to obtain the context path is:

Richard Green
Ranch Hand

Joined: Aug 25, 2005
Posts: 536
I use the Firefox browser and I have the web-developer extension installed. (

It comes with a handy tool to find the broken images (Images > Find Broken Images).

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