| Author |
JSP page not displaying the image
|
tarun bansal
Greenhorn
Joined: Mar 21, 2006
Posts: 11
|
|
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
Joined: Mar 22, 2006
Posts: 48
|
|
Hi tarun This can sometimes happen when using relative paths. you can try giving the absolute path/ path from root cheers!
|
to err is human, but the company policy doesn't allow it!
|
 |
Chetan Parekh
Ranch Hand
Joined: Sep 16, 2004
Posts: 3636
|
|
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">.
|
My blood is tested +ve for Java.
|
 |
Stefan Evans
Bartender
Joined: Jul 06, 2005
Posts: 1005
|
|
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
Joined: Jan 10, 2002
Posts: 56192
|
|
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 ]
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Richard Green
Ranch Hand
Joined: Aug 25, 2005
Posts: 536
|
|
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
|
MCSD, SCJP, SCWCD, SCBCD, SCJD (in progress - URLybird 1.2.1)
|
 |
 |
|
|
subject: JSP page not displaying the image
|
|
|