How to change a IMG SRC using java in JSP?

1.8k 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 best solutions below

0
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
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..