tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher Schultz <>
Subject Re: no temp directory creation wanted when embedding Tomcat
Date Wed, 24 Apr 2019 16:13:35 GMT
Hash: SHA256


On 4/23/19 16:46, Garret Wilson wrote:
> On 4/22/2019 7:58 AM, Mark Thomas wrote:
>> On 21/04/2019 15:53, Garret Wilson wrote:
>>> … But now I realize Tomcat is creating this directory structur
>>> inside the "base dir" I specified:
>>> tomcat.8080/work/Tomcat/localhost/ROOT
>>> I don't need this directory. I don't want this directory
>>> created. How do I tell Tomcat not to create no danged
>>> directories?
>> The Servlet specification requires (see section 4.8.1 of the
>> Servlet 4.0 spec) that Tomcat provides a private temporary
>> directory for each servlet context (web application).
> I have have several reactions.
> 1. The first is, OK, so the servlet spec requires that the servlet 
> container expose a temporary directory. Tomcat can't provide a
> temporary directory to the consumer unless it has a temporary
> directory, so it's reasonable that it creates one.
> 2. But so far nothing has been stored in this directory, so it's 
> completely unused. I see also in the `Tomcat` class the comment,
> "lazy init for the temp dir - only when a JSP is compiled or get
> temp dir is called we need to create it. This will avoid the need
> for the baseDir". It sounds like you're lazily creating the JSP
> temporary directory, so why can't we do the same for the context
> temporary directory, which may never be used (and frankly probably
> won't be used in many applications)? But OK, that's a quibble; my
> other thoughts are more pressing.

Lazy-creation of the directory cannot be accomplished simply. This is
because there is no API call to get the temp directory that will be
used by the context. Or, rather, the API call is too generic. This is
how a web application should use a temporary directory from within
e.g. a servlet:

File tmpDir = (File)
File myFile = new File(tmpDir, "my.file");
// Use myFile...

The only API call to intercept would be ServletContext.getAttribute,
and we'd have to look specifically for the TEMPDIR attribute key.

This can indeed be done, at varying levels of laziness (on the part of
either the Tomcat programmer, or by the code itself to delay as long
as possible).

> 4. But all this "temporary directory requirement" business is for 
> servlet containers. I started out just wanted to embed Tomcat to
> serve static files; I don't (yet? ever?) need a servlet container
> for this particular application. So how can I use Tomcat to serve
> static files without bringing in the requirements of a servlet
> container?

Tomcat is a servlet container. Just because you don't care to use it
as such doesn't mean that Tomcat should be re-architected.

> Maybe the answer is that Tomcat serves files by using a 
> static-file-serving servlet

It does.

> which in turn requires me to use Tomcat as a servlet container even
> for serving static files, which in turn requires me to have a
> temporary directory I don't want or need.

Yes, but I don't believe the DefaultServlet uses the temporary
directory for anything, here. (DefaultServlet does use the temp dir,
but it only uses it for PUT operations.)

> I suppose that's just the way it is. This is not so much a
> complaint as a desire to confirm I understand correctly how things
> stands. (OK, it's a teeny-tiny complaint, too.)

- -chris
Comment: Using GnuPG with Thunderbird -


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

View raw message