-1

I am stored an image in postgres sql as bytea[] field.That is in byte format.I want to view the perfect image into my jsp page after storing the image.Please, point me to the solution or some ways to achieve this requirement.

1

1 Answer 1

1

Covert your image to Base64:

String imageBase64 = new String(Base64.getEncoder().encode(imageByteArray)) 

Note that Base64 class is coming from java.util package. If you not using JDK 8 you can easily find an alternative to do that.

Then in your JSP page:

<img src="data:image/png;base64,${imageBase64}" /> 
Sign up to request clarification or add additional context in comments.

3 Comments

Thank you for the reply.I tried the code.But problem is the same.
This is the right way to do it. Please amend your question with the details of what exactly is not working.
Thank you sir for the reply...I got the answer.Only one change is there to view the image.<img src="data:image/png;base64,<%=imageBase64%>" >

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.