This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes JSP and the fly likes JSP - How to link url to an image? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "JSP - How to link url to an image?" Watch "JSP - How to link url to an image?" New topic
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: 61450
    
  67

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!


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by 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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSP - How to link url to an image?