Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSP - How to link url to an image?

 
Ram Sudheer Mandava
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?
 
Pawan Kr Gupta
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.
 
Shashank Ag
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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64623
86
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic