• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Displaying image from database

 
Aravind Prasad
Ranch Hand
Posts: 265
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 265
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thankyou very much Ulf

It can work well now!!

Regards

Aravind Prasad
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic