This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes JSP and the fly likes Display images in a JSP page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Java » JSP
Bookmark "Display images in a JSP page" Watch "Display images in a JSP page" New topic

Display images in a JSP page

Chatura Dilan
Ranch Hand

Joined: Feb 13, 2007
Posts: 44
I have created an ArrayList which contains Member objects. Each Member object has an attribute called picture (Data type is byte[]).
I need to show all pictures in one JSP page and I like to use <img> tags for that.
How can I do that? Any ideas

-----------------------------------<br />If at first you don't succeed, try again without cry. Everytime You will learn what not to do next time, untill you succeed.<br /> <br />SCJP 1.4 (78%)<br />SCWCD 5 (95%)<br />BICT - UCSC
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

Yes, in your JSP, create images tags (one for each element in the array).
Then, create a servlet that can respond to the image request by streaming the bytes down to the client; with the correct mime and disposition headers, of course.

The closest thing I can offer you is a demo project that I wrote which streams an image to the browser using context.getResourceAsStream.
Look for SimpleStream

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Chatura Dilan
Ranch Hand

Joined: Feb 13, 2007
Posts: 44
Ben Thanks for your reply
I agree. Here's the link:
subject: Display images in a JSP page
It's not a secret anymore!