tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher Schultz <>
Subject Re: Trying to access a directory outside docBase... is it possible ?
Date Tue, 15 Dec 2009 18:44:59 GMT
Hash: SHA1


On 12/15/2009 11:05 AM, Peter Crowther wrote:
> If you're going to do this, be Very Very Careful.  Tomcat doesn't follow
> symbolic links by default, even on UNIX.  This is for a very good reason: if
> you do this, Tomcat *will* follow the symlink and delete your PDFs when you
> undeploy your webapp.
> You probably don't want this to happen.

+1 :)

> This is a common enough use case (it comes up about once a month on the
> list) that Someone may have coded a quick "serve the content from this
> directory" servlet, probably based on the root webapp.  Chris?  You're
> generally the coder with quick hacks already developed...

Uh, file-serving code is pretty simple: set the Content-Type and
Content-Length headers, open the file, deliver the bytes.

It's so popular that it's already been written and even ships with
Tomcat: it's called the DefaultServlet :)

Seriously, though, Ingo was very close to a working solution:

> I stumbled over a hint about adding a 
>   <Context  docBase="/opt/documents" path="/documents"/>
> directive to the web.xml file

Ohh! So close! That should be added to conf/server.xml (but not really,
since that's no longer recommended). Let's do it the right way:

Put this into conf/Catalina/localhost/document-repository.xml:

   <Context docBase="/opt/document-repository" path="/documents" />

I think you might have to restart Tomcat for it to pick up that config
file, but it will create a new webapp context that serves files directly
from that location. Your URLs will no longer look like this:


Instead, they can look just like this:


You can even get rid of your PDFViewer servlet, because it's probably
just serving bytes and not doing anything particularly exciting.

- -chris
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla -


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

View raw message