I have been banging my head over this for awhile now and google's no help. so any suggestions would be greatly appreciated.
We save image thumbnails in a MySQL Database. Please,please do not tell me to switch to a filesystem as this decision was made after a lot of gut-wrenching debate and we are well into the dev cycle to change design.
I wrote a simple
servlet that when passed the image ID fetches the blob and streams it to the http response stream:
byte[] rb = ...call db and stream blob to byte array here...
response.setContentType("image/jpg");
response.getOutputStream().write(rb,0,len);
I then call this servlet from the image src tag like so
<img src="ImageServlet?id=123"...>
Everything works fine so far.
The requirement is now to display multiple thumbnails on a single page(Say 5 rows of 4 thumbnails each)
If i use the above setup then the page would fire multiple(20!) queries to fetch all the images. This is what i wish to avoid and where iam stuck. My alternatives:
Option 1) A new servlet takes 20 image IDs and caches them somehow(?). This would involve either saving the files in user session or writing to webserver which would quickly overwhelm resources when 100s of users request 1000s of pages.
Option 2) Preload images in the
jsp. Im not sure if this can be done. need to write some
test code and see.
So there you have it. If any gurus out there have experience with showing multiple images from a database then please do share your experience. Any insights/suggestions/links/critiques welcome.
Meanwhile, I will keep looking and keep you posted on my findings.
Many Thanks
Mark in the Dark