aspose file tools*
The moose likes JSP and the fly likes Displaying image from database 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 » JSP
Bookmark "Displaying image from database" Watch "Displaying image from database" New topic
Author

Displaying image from database

Aravind Prasad
Ranch Hand

Joined: Dec 28, 2005
Posts: 265
Dear Ranchers,

I am doing a project in JSP and MySQL. I have the image inserted in the database. I have to retrieve the image and display it in the jsp page. I am using a framework in such a way, the class files will connect to the database and retrieve the table values and save it in the hash map.



it is retrieving the image and store in the HashMap like this



How can I put the emp_photo in the jsp page.

Please assist me.

Thanks and Regards

Aravind Prasad

[ UD: fixed code layout ]
[ November 17, 2007: Message edited by: Ulf Dittmer ]
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42908
    
  69
What kind of object is that that you have stored in the database? A byte array[] of an image? Is it in a web-compatible format (GIF, JPEG, PNG)?

Either way, you can't do this in a JSP - you'll need a servlet for it. JSPs can handle text, but not binary data. The JSP page that includes the image should have an image tag that has a "src" attribute pointing to the servlet that retrieves the image. The servlet would then stream the image data to the browser, setting the content type according to the image format. The CodeBarn contains an example of how to do that.
Aravind Prasad
Ranch Hand

Joined: Dec 28, 2005
Posts: 265
Thankyou very much Ulf

It can work well now!!

Regards

Aravind Prasad
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Displaying image from database