File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Displaying images stored in the database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Displaying images stored in the database" Watch "Displaying images stored in the database" New topic
Author

Displaying images stored in the database

Mary White
Ranch Hand

Joined: Jan 27, 2003
Posts: 41
Hi,
I'm saving image files (bmp, jpg, gif) in the database as binary data (I'm using SQL Server). Then, I have to retrieve this file and show the image in a JSP.
I'm using Struts 1.1, SQLServer and weblogic.
How can I do this?
Thanks
alzamabar
Ranch Hand

Joined: Jul 24, 2002
Posts: 379
I would suggest first to get a connection to the database and in someway to get a Collection of 'binary data images'; then, applying the same pattern used to convert images from their format to binary format, but on the way back, use the <html:image> Struts tag to display it on your page.
My 2 cents.


Marco Tedone<br />SCJP1.4,SCJP5,SCBCD,SCWCD
Dave Hewitson
Greenhorn

Joined: Jun 01, 2001
Posts: 27
I was looking for a good solution to the same problem a couple of months back.
This solution may not be the best, but It was the only one I could find at the time - performance was ok using MySQL but awful on DB2 - you'll have to see for yourself.
Anyway, I used a helper servlet to get the binary data from the DB - here's the code...

The in my jsp I have...

Hope this helps.
Regards
Dave.
Mary White
Ranch Hand

Joined: Jan 27, 2003
Posts: 41
Thanks Dave, your suggestion was really good
Graham Mead
Ranch Hand

Joined: Sep 28, 2001
Posts: 57
Hi Mary
Not used it myself but you could have a butchers at the JDBC 2.0 Blob interface
Found these links
http://java.sun.com/j2se/1.4/docs/guide/jdbc/blob.html
http://developer.java.sun.com/developer/onlineTraining/Database/JDBC20Intro/exercises/BLOBGet/index.html
The interface seems to reduce the amount of code you need to write but it might be an alternative.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Displaying images stored in the database
 
Similar Threads
JTable binding using JPA
How can i display image .bmp in a JSP !!! Thanks !!!
Uploading and Downloading a file
thumbnail in jsp
Putting an image on JSP