I worked on an app where we had cache set to false for Struts. In that context, using an Action to retrieve the images prevented any of them from being cached, which was bad for server load and site performance. We were using Struts 1.0.2, though perhaps Struts 1.1 allows you to set the cache behavior of each mapping/Action individually, which would have solved our performance issue for the most part.
In light of that, we wrote a little servlet to serve the images. We also implemented getLastModified() to retrieve the last modification time of the requested image (which was also stored in the database). This worked great, because the images would be cached by the browser until they were updated in the db. I am not sure if that (last modification time) is supported in Struts 1.1 either, but it would be another nice thing to have for applications like this. As a side note, storing the images in the db was been very nice for us generally. Having all the data in the database is very convenient for deployment, since there are no filesystems to worry about and no chance that the filesystem would be out of sync with the db (where you would likely still store references to the binary data, stored as files in such a scenario). The performance was fine with the caching sorted out. We didn't do any rigorous comparisons to disk-based storage, but rather the performance just turned out to not be an issue for this project after the caching was fixed. Perhaps this already exists, but it would be very cool to have a system that stored (or simply allowed storage of) the image (or any similar binary data) in the db and then cached them to a local disk for performance. This would be a great J2EE or Struts-specific open source project for someone to make available. You'd get the convenience of db storage and the performance of disk storage. You could even provide a custom tag library to construct a tag (or URL) from the image/resource ID, set the size of image in the HTML, or perhaps adjust the src URL for direct access to the disk file for cached images. Though watch out for stale caches in that last scenario -- perhaps the mod times of the disk file versus the db blob could be checked when the tag is processed to avoid that problem. The image could even be pre-emptively written to the cache (assuming it is stale or not yet cached) when the tag is processed to always be able to write a URL to the file in the cache rather than to a servlet for processing. You might run into trouble if someone references the image from another site or something though, so that might not be that great after all. That is unless you have a 404 handler that could look it up in the cache if it is found to be missing on disk and reset the response code back to 200 and serve the image data from the db, which might be worth a try. The 404 handler idea would allow operation with a fixed maximum disk cache size, or avoid problems if you simply ran out of disk space to cache to, also. Or perhaps it would be simpler and just as fast to pass all requests for images through a servlet, since you'd be doing much the same kind of stuff that the FileServlet would be doing to serve the image anyway. Non-image specific tags would also be useful for other kinds of binary data stored in the db. This could be a great project if there isn't one out there already. -Max ----- Original Message ----- From: "Nicolas De Loof" <[EMAIL PROTECTED]> To: "Struts Users Mailing List" <[EMAIL PROTECTED]> Sent: Wednesday, April 02, 2003 12:46 AM Subject: Re: How to use Struts to show image from database (byte[])? > You can migrate your original ImageServlet as Struts action : > > Put servlet code inside execute() method of a new ImageAction class, that sends image byte[] and content-type headers in > response, then returns null. > > Add an action-mapping for ImageAction (let's say "/image.do") and you will be able to use "/myApp/image.do?imageID=x" > > Nico. > > > > Subject: How to use Struts to show image from database (byte[])? > > > I have images in database. > Prior to Struts I use servlet to show image and in JSP or sevlet. I have /myPackage/imageservlet?imageID=1 > > How to use Struts to show image from database (byte[])? > > Thanks. > > > --------------------------------------------------------------------- > 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]