imageiostruts2

How to retrieve images from server to user using Struts 2


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

Products images after obtaining from user will be saved in directory:

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

And when 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 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.