• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JSP page not displaying the image

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Ranch Hand
Posts: 3640
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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">.
 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 536
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
My, my, aren't you a big fella. Here, have a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic