• 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

Show Image from MySQL on JSP

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I have made a picture search database using struts2 and MySQL. I am able to store pictures in MySQL as BLOB datatype using struts2. Now I want to retrieve(search) those pictures and show them back on JSP. I can retrieve and store picture in byte[] variable in action but, don't understand how to pass it to JSP for display.

Could anyone please guide me what is the best approach for doing this. I don't want to save picture on disk and then display. If it's possible that I can directly retrieve and display, that would be great.

Appreciate your help and time.

Thanks
 
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You wouldn't pass the byte array to a JSP. That's because a JSP is for producing something (usually HTML) in a text format. Images are not in a text format.

The thing to do with your byte array is to just copy it to the servlet response's output stream. You will also have to set the response's content type to something which matches the image format. For more information read the Ranch's FAQ about that: Image Servlet .
 
shally kumar
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Paul. That was good link, just I was having some difficulties in implementing it. So, finally I decided to change my strategy and instead of uploading/downloading pictures from MySQL, I changed it to upload/retrieve from file system (root directory) and save the metadata in the database.

Thanks again.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic