We do the following:
We've got graphics stored as a blob in an oracle database.
We create a servlet that can, given a mapping of some kind, look up the graphic in the db and returns it to the client.
Our anchors are then setup like:
Our web app is deployed to the /webapp context above, and the servlet is mapped to /GetImage/*
The servlet gets the request, looks up the image in the db( from above, "imagename.gif"), sets the ContentType to "image/gif" (or whatever) and the content length, and returns the data stream to the client. No need to write anything to the filesystem at all.
Actually, we end up using an LRU caching system, to avoid hits to the DB (since our images really don't change once created).