• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

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
 
But how did the elephant get like that? What did you do? I think all we can do now is read this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic