• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSP page not displaying the image

 
tarun bansal
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

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
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi tarun

This can sometimes happen when using relative paths.

you can try giving the absolute path/ path from root

cheers!
 
Chetan Parekh
Ranch Hand
Posts: 3640
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by tarun bansal:
Hi

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





Try with <img src="./images/tarun.jsp">.
 
Stefan Evans
Bartender
Posts: 1691
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
or probably better

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

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

Cheers,
evnafets

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
Marshal
Pie
Posts: 64717
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Richard Green
Ranch Hand
Posts: 536
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.,

http://localhost/yourWebApp/tarun.jpg

Hope this helps
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic