imagejspiostruts2imageurl

How to retrieve images from server and show them on JSP page in Struts 2?


I have a Product entity, which has a imageUrl string field.

Product's images, after obtaining from the user, will be saved in directory:

System.getProperty("user.home") + "shop/data/product/"

And, when the user wants to see some Product, I need to get this image from "user.home"+... to JSP page.

I've tried to read the image into the byte array, convert it to Base64 encoding, and then refer in JSP like this:

<img alt="image from user home" src="data:image/png, base64;${requestScope.image}">

But, this solution is not working, and as far as I understand, it has a limitation on the image size.

Could you suggest me a way how to do such thing?


Solution

  • Try this ( i think you have some typo )

    <img alt="image from user home" src="data:image/png;base64,${requestScope.image}">
    

    Also use this site: http://www.askapache.com/online-tools/base64-image-converter/ to make sure that your output Base64 code is correct.