File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes display image from bytearray Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "display image from bytearray" Watch "display image from bytearray" New topic
Author

display image from bytearray

nikki sinha
Greenhorn

Joined: Jul 04, 2012
Posts: 14
hi,
i am trying to convert a byte array of image into image and want to display in JSP page. i am able to save the picture in any location but cant display it in the web page.

here is my code

byte[] decoded = //the decoded base64 string in bytes.

BufferedImage bufferedImage = ImageIO.read(new ByteArrayInputStream(decoded));
File imageFile = new File("E:/profile.jpg");
ImageIO.write(bufferedImage,"jpg", imageFile);

this is working fine... the image gets store in the given location. but when i pass it through outputstream, it does not print it in the JSP page.

byte[] decoded = //the decoded base64 string in bytes.

BufferedImage bufferedImage = ImageIO.read(new ByteArrayInputStream(decoded));
OutputStream out = response.getOutputStream();
ImageIO.write(bufferedImage, "jpg", out);
out.flush();
out.close();

how can i print it in a new jsp file.....

please help...
thank you...

William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12835
    
    5
Exactly how does the IMG tag in the HTML written by the JSP refer to the image source?

Bill
nikki sinha
Greenhorn

Joined: Jul 04, 2012
Posts: 14
William Brogden wrote:Exactly how does the IMG tag in the HTML written by the JSP refer to the image source?

Bill


i am a little confused about this... but what i did is using the url pattern of the servlet given in the web.xml


userimage is my servlet
if i am wrong then please correct me
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12835
    
    5
Whatever image you tried to paste into your post is not showing in my browser. It is much more useful to cut and paste the actual text from web.xml - kindly use the "code" tags.

Also kindly show the exact URL as you have formulated it in the HTML written by your JSP - use your browser's "view source" capability to get the exact text.

Bill
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: display image from bytearray