• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Displaying image from database

 
Ranch Hand
Posts: 265
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thankyou very much Ulf

It can work well now!!

Regards

Aravind Prasad
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic