How to change a IMG SRC using java in JSP?

1.7k views Asked by At

I try change an image source by this code:

<img src="<% "http://www.image.com"; %>" alt="image" height="190" width="190" id = "picture"> 

But it won't display the image.

2

There are 2 answers

0
Saurabh Jhunjhunwala On

why don't you change the double quotes to single quote and try

<img src='<% "http://www.image.com"; %>' alt="image" height="190" width="190" id = "picture" />
1
Pavan Kumar K On

You can use JSP scriptlet.

<img src="<%= url_var %>" alt="image" height="190" width="190" id="picture">

url_var is a java variable here, which puts the value into the src attribute.

Hope this helps you..