This week's book giveaway is in the Java in General forum.
We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line!
See this thread for details.
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

images not showing

 
Patricia Murphy
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64827
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Naveen Kumar
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64827
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 536
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic