You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Ingo Gambin <IG...@brilliant.de> on 2009/12/16 07:33:39 UTC

Re: Trying to access a directory outside docBase... is possible !

Hi,

thanks a lot!

Using the 'deprecated' way of putting the '<Context docBase...>'
directive to server.xml worked whereas trying to put it into
documents.xml in the localhost directory did not (using Tomcat 5.5).

I am using an extra servlet for the viewer because I dont want to reload
the whole page but still want to set my session variables to the values
sent via the link (file=... page=...), which I can easily do in the 
viewer servlet.

Thanks again for all the ideas and information, I think I did learn
a few things by your responses... especially the 'symbolic link'-hint as
I was about to try that first thing this morning, good I read mails
first. 

Best regards and CU when I encounter my next problem:-)

Ingo

Am Dienstag, den 15.12.2009, 13:44 -0500 schrieb Christopher Schultz:
> -----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
>