wood burning stoves 2.0*
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "images not showing" Watch "images not showing" New topic
Author

images not showing

Patricia Murphy
Greenhorn

Joined: Feb 22, 2006
Posts: 5
Hi

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?

Thanks
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60774
    
  65

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.

So...

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


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

Joined: Dec 14, 2006
Posts: 35
Hi

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>


Regards
kumar
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60774
    
  65

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:

${pageContext.request.contextPath}
Richard Green
Ranch Hand

Joined: Aug 25, 2005
Posts: 536
I use the Firefox browser and I have the web-developer extension installed. (http://chrispederick.com/work/webdeveloper/)

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: http://aspose.com/file-tools
 
subject: images not showing
 
Similar Threads
Web application deployment
for generating chart
Need suggestion regarding an issue related to content type header
Images don't show
problem with Links which address jsp page in subdirectpry of www root