| Author |
JSP - How to link url to an image?
|
Ram Sudheer Mandava
Greenhorn
Joined: Aug 04, 2010
Posts: 22
|
|
Hi,
How to link the url to an image? Why the following code is not working?
<% String Logo = null;
if (httpSession.getAttribute("Logo")!=null) Logo = (String) httpSession.getAttribute("Logo"); %>
<% if(Logo!=null){%>
<%if(Logo.equalsIgnoreCase("image.jpeg")){%>
<a href="http://www.google.com/" target="_self">
<img src="pics/image.jpg" border="0" alt="Logo"></a>
<%}else{%>
<img src="pics/<%=Logo%>" alt="Logo"/><%}}%>
Any one please help me on this. When I'm hitting the image it is not opening the google page. I'm not getting any error message. Is it possible to write like this in "if" block?
|
 |
Pawan Kr Gupta
Greenhorn
Joined: Nov 21, 2010
Posts: 26
|
|
You code is right , please check the value that is present.I have written the below line of codes that are working fine.
|
 |
Shashank Ag
Ranch Hand
Joined: Dec 22, 2009
Posts: 88
|
|
"httpSession" is not name of implicit object instead "session" is.
Besides, did I mentioned that scriplet coding is really really bad practice.
|
SCJP 91%, SCWCD 97%
|
 |
Ram Sudheer Mandava
Greenhorn
Joined: Aug 04, 2010
Posts: 22
|
|
Hi,
The image is getting from HttpSession and displaying in the page but I'm unable to link to the url.
|
 |
Shashank Ag
Ranch Hand
Joined: Dec 22, 2009
Posts: 88
|
|
I don't know how you are sure about this (seeing your code). But, try to place different images in if and else tags to be sure of it.
Because as i see your code is going in else part.
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56151
|
|
When it comes down to it, all that matters is what is sent to the browser. Does the <img> tag look right when you view the browser source?
P.S. It still completely blows me away that people thinks it's acceptable to put scriptlets and Java code into JSPs in 2011!
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Ram Sudheer Mandava
Greenhorn
Joined: Aug 04, 2010
Posts: 22
|
|
Sorry I placed wrong extension in if condition. I corrected it now it is working fine
Thanks
|
 |
 |
|
|
subject: JSP - How to link url to an image?
|
|
|