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 Answer
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}" /> 3 Comments
Gayathri Rajan
Thank you for the reply.I tried the code.But problem is the same.
Paulius Matulionis
This is the right way to do it. Please amend your question with the details of what exactly is not working.
Gayathri Rajan
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%>" >