I've seen this conversation before so I don't think I am saying anything
outlandish here.

There is a performance overhead from reading a database to present to the
JSP page, however you look at it. There is nothing wrong with writing the
image once to the file system, and storing a reference to the image on the
file system.

-----Original Message-----
From: Braun, James F [mailto:[EMAIL PROTECTED] 
Sent: 27 September 2005 17:24
To: Struts Users Mailing List
Subject: writing images from a database

Goal: Read a blob image from an Oracle database and render it on an html
page using the struts framework.

I've never found a good way to do this and I was hoping someone had a
"best practice" suggestion.

I have no trouble getting the image from the database. However, I wonder
if there isn't a better way to display it rather than writing it to a
physical file and then rendering it. I'm using the <html:img tag to
display the image now.

All help appreciated.

J.

ImputStream pictureStream;
ResultSet rs;

// create the query and execute it ...

// get the result
pictureStream = rs.getBinaryStream("picture");

// I can write it to a physical file
File pictureFile = new File("/temp/picture.jpg");

        try
        {
          FileOutputStream out = new FileOutputStream(pictureFile);
          int chunk = 0;
          while( (chunk = pictureStream.read()) != -1)
          {
            out.write(chunk);
          }
          out.close();
          out.flush();
        }
        catch(FileNotFoundException ex)
        {
          System.err.println("selectionForm.populate.picturefile: " +
ex.getMessage());
          logger.error("selectionForm.populate.picturefile: " +
ex.getMessage());
        }
        catch(IOException ex)
        {
          System.err.println("selectionForm.populate.picturefile: " +
ex.getMessage());
          logger.error("selectionForm.populate.picturefile: " +
ex.getMessage());
        }

-- 
This transmission is intended only for use by the addressee(s) named herein
and may contain information that is proprietary, confidential and/or legally
privileged. If you are not the intended recipient, you are hereby notified
that any disclosure, copying, distribution, or use of the information
contained herein (including any reliance thereon) is STRICTLY PROHIBITED. If
you received this transmission in error, please immediately contact the
sender and destroy the material in its entirety, whether in electronic or
hard copy format. Thank you.



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to