tomcat-users mailing list archives

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

Peter,

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:

http://localhost:8080/myApp/PDFViewer?file=document-repository/Folder%202/TestDok4.pdf&page=1

Instead, they can look just like this:

/documents/Folder%202/TestDok4.pdf&page=1

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

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAksn2SsACgkQ9CaO5/Lv0PDlQACglU4lGn9398YVUBpjMGtbJP2X
beoAn1zI4YyBJe9sr2MYZOSdlyCqXi3o
=RPfr
-----END PGP SIGNATURE-----

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


Mime
View raw message