• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

JSP - How to link url to an image?  RSS feed

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You code is right , please check the value that is present.I have written the below line of codes that are working fine.
 
Ranch Hand
Posts: 88
Java Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"httpSession" is not name of implicit object instead "session" is.
Besides, did I mentioned that scriplet coding is really really bad practice.
 
Ram Sudheer Mandava
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 88
Java Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Author and ninkuma
Marshal
Posts: 66823
168
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Ram Sudheer Mandava
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry I placed wrong extension in if condition. I corrected it now it is working fine
Thanks
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!