tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sebb <>
Subject Re: storing images
Date Fri, 06 May 2011 13:05:14 GMT
If multiple threads try to create the image at the same time it is
possible that one thread will see a partial file - or the file may be

If you are not doing this already, I suggest creating the file with a
unique temporary name and then renaming it once complete.
The rename may fail if another thread has meanwhile created it, but
that can easily be allowed for.

Trying to lock the file whilst it is created is likely to be harder to
implement; however it might be worth it if the file creation is very
expensive in system resources.

On 6 May 2011 13:48, Thad Humphries <> wrote:
> I'd store the image to and retrieve it with a servlet. I
> doing this now with my Ajax application.
> On Thu, May 5, 2011 at 2:19 PM, alexis <> wrote:
>> Hello all, im facing an issue, ive been testing for a while different
>> approaches without success.
>> I have a servlet that basically does
>> . creates an image
>> . store the image on disk
>> . returns an html <img> tag pointing to the stored image.
>> reason why the servlet doesnt returns the image directly using a response
>> type image/png is the servlet is called from an ajax script, this ajax
>> script renders the inner text inside a div on a jsp page on the same context
>> that the server runs. ajax can only render html on divs, there's no way to
>> return binary content (the image) from the servlet to the ajax script.
>> So, i have to create the image on the servlet (done) , store the image on
>> the disk (done), and return the <img> tab also done. Thing is, where im able
>> to store the image from the servlet im not able to read it from the jsp.
>> I tried with /tmp, i tried with servletcontext.getpath to store the file on
>> that dir, nothing seems to work. where should i store and reference those
>> images to be written by the servlet and read by the jsp?
>> thanks in advance
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail:
>> For additional commands, e-mail:
> --
> "Hell hath no limits, nor is circumscrib'd In one self-place; but where we
> are is hell, And where hell is, there must we ever be" --Christopher
> Marlowe, *Doctor Faustus* (v, 121-24)

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message