I'm getting an image url from my database and need to display it in an <img> tag. The problem I have is that JSF is encoding &'s as & and the image url is not found.
Here's an example. The correct image url:
https://<server details>?ahid=2096&aid=107687&lid=28812968&url=202.jpg The encoded url:
https://<server details>?ahid=2096&aid=107687&lid=28812968&url=202.jpg In this case the encoded image url is not found and displays the broken image icon. How do I solve this?
EDIT: the html elements with their JSF tags:
<a href='#{product.itemUrl}' target="_blank"> <img src='#{searchResults.getThumbnailUrl(product)}' class="img-responsive imageproduct" /> </a> EDIT 2:
I thought I'd try replacing the & back to & with javascript but this doesn't work either because in the javascript the image url is fine, while in the browser's view source it's not. Here's the code. In the browser:
<img id="thumbnailId" onmouseover="decodeUrl(this)" src="https://www.proxibid.com/asp/LotImageViewer.asp?ahid=3231&aid=108183&lid=28955872&url=144-1.jpg" /> The javascript:
function decodeUrl(img) { var url = img.src; console.log("url before = " + url); url = replaceAll(url, "&", "&"); console.log("url after = " + url); } function replaceAll(str, find, replace) { return str.replace(new RegExp(find, 'g'), replace); } The output is
url before = https://www.proxibid.com/asp/LotImageViewer.asp?ahid=3231&aid=108183&lid=28955872&url=144-1.jpg url after = https://www.proxibid.com/asp/LotImageViewer.asp?ahid=3231&aid=108183&lid=28955872&url=144-1.jpg as you can see the two are identical, and correct. But doing a view source results in
src="https://www.proxibid.com/asp/LotImageViewer.asp?ahid=3231&aid=108183&lid=28955872&url=144-1.jpg" which is incorrect, and the image is broken. Any idea how to fix this?
&has to be encoded as&, so if you look at the html code your image url has to look like this<img src="https://<server details>?ahid=2096&aid=107687&lid=28812968&url=202.jpg" >the browser will automatically convert that url tohttps://<server details>?ahid=2096&aid=107687&lid=28812968&url=202.jpgwhen requesting the image. I would guess you have some double encoding and that your source actually contains&amp;:<img src="https://<server details>?ahid=2096&amp;aid=107687&amp;lid=28812968&amp;url=202.jpg" ><img>elements?