Win a copy of Microservices Testing (Live Project) this week in the Spring forum!
  • 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
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

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: 67650
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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic