Hi

I'll try to explain in as few words as possible.

When I upload a new product I store the image data and the text in the
database. I did this to try and separate the data from the application
 with the intention of eventually having the data reside on a separate
device optimised for serving data ... well that was my original
thinking anyway.

At the moment, when I load an image I use a proxy servlet and extract
the imageid from the 'Product' (p below)

<img src="ImageProxy?<%=WebConstants.IMAGE_ID%>=<%=p.calculateImageId()%>...
etc '/>

This gets the image from the database and displays it in the page.

This is clunky and slow and the image is not cached by the browser

So, when a user views an item detail I do something like this

getProductDetails?productId='whatever'

In the GetProductDetails servlet I check the disk cache to see if the
image is there, if not I get it from the database an write it to the
cache, just one database access as opposed to many, the next time
anyone sees that item the images are already cached.

now, in the jsp I can use <img
src="imagecache/<%=p.getProductId()%>_thumb.jpg"  ...' etc/>

In other words, as opposed to getting an anonymous byte stream and
displaying it in the browser I'm now accessing a named image and the
browser caches it. It all works beautifully apart from the fact that
it appears the DefaultServlet will not load resources that have been
written to disk after the server has been started. If I restart the
server I can see my images, but only the ones loaded thus far ...

Anyway, I'm currently looking at the serveResource() method in the
DefaultServlet to try and figure out if it is possible to configure it
to load resoures that have appeared after the server has started ...
it doesn't look like it is possible which is slightly depressing ...
unless of course I am missing something.

Surely this is not an unusual requirement, how do others deal with
serving up images that have been uploaded after the server has
started.

Anyway

Thanks for taking the time to reply
lyallex


2009/6/10 Jonathan Mast <jhmast.develo...@gmail.com>:
> So you are actually storing the image data in the database, as opposed to
> the filepath? interesting...
>
> So your webapp accesses the image data as needed and writes it to imagecache
> dir?  Is this feature not working? i don't understand what exactly the issue
> is that you are having.  please explain.
>
>
>
> On Wed, Jun 10, 2009 at 9:41 AM, Lyallex <lyal...@gmail.com> wrote:
>
>> apache-tomcat-6.0.16
>> jdk1.6.0_03
>>
>> Dev box : Windows
>> Deployment box: Linux
>>
>> Hi
>>
>> I've read some other posts that seem to be asking similar questions
>> but I can't find the answer so far.
>> maybe someone here would be kind enough to give me a hint
>>
>> I have a retail application that stores the product images in a database.
>> Each product can have many images and products are being uploaded all the
>> time.
>>
>> Fetching images from the database every time results in a clunky page
>> load so I want to cache the images to disk
>> the first time an item is accessed my cache manager checks the disk
>> cache to see if images for that item are available.
>> If not it loads them onto the disk.
>> this happens in the servlet that serves the item details up so the
>> images are in the disk cache before the request is forwarded to the
>> view (jsp)
>> In the jsp I access the images from the disk cache.
>>
>> The problem is, the first time I access the item details the images
>> are written to the cache which resides directly under the
>> context root but they are not loaded in the view.
>> If I restart tomcat the images disply fine so I know all the caching
>> is working correctly.
>>
>> I can't restart tomcat everytime I upload a new product so how can I
>> force tomcat to recognise the new images 'on the fly' so as to speak?
>> The application is running as the ROOT application on the server and
>> is the only application being served.
>>
>> An example image might be
>> ../apache-tomcat-6.0.16/webapps/ROOT/imagecache/8000030_main.jpg
>> (example)
>>
>> I'm quite happy that the imagecache is deleted everytime I redeploy
>> the application because the application is starting to stabilise and
>> once I have this last problem ironed out
>> I will only be doing irregular maintenance. The faster loading of
>> images is more than enough compensation.
>>
>> I can't use symbolic links to place the imagecache outside the
>> application space because I develop on Windows and deploy to Linux
>> (historical, nothing I can do about it)
>>
>> Any ideas much appreciated.
>>
>>
>> Many thanks
>> lyallex
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
>> For additional commands, e-mail: users-h...@tomcat.apache.org
>>
>>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to