1

I having image byte array in app_be.getBytes().

BufferedImage img = ImageIO.read(new ByteArrayInputStream(app_be.getBytes()));

i having this line in my jsp.I got image in img.how can i display this image in my jsp img tag can u help me. other than this image all working properly. Like this i want to print tat img can u please help me

<img src="<%= img%>" height="100%" width="100%" >

i tried like this <img src="<%= img.getSource()%>" height="100%" width="100%" > but tat also not working i dont know how to display img plz help me.

sabarirajan
  • 177
  • 2
  • 3
  • 13
  • 1
    see http://stackoverflow.com/questions/2438375/how-to-convert-bufferedimage-to-image-to-display-on-jsp – Ashok Damani Jun 15 '13 at 05:49
  • ashokdamani s i already tried tat way its working.in servlet.i took tat byte array in jsp i want to process here and want to display plz help for tat. – sabarirajan Jun 15 '13 at 06:05

1 Answers1

0

Try this code inside your servlet

BufferedImage image=ImageIO.read(new File("filepath");
ByteArrayOutputStream byteArrayOS=new ByteArrayOutputStream();
ImageIO.write(image, "jpg", byteArrayOS);
byte [] byteArray=byteArrayOS.toByteArray();
photo="data:image/jpg;base64,"+Base64.encode(byteArray);

print the value of photo in your jsp as

<img height="100px" src="${photo}" alt="Photo" />

This worked for me . have a glance over this