• Post Reply Bookmark Topic Watch Topic
  • New Topic

Add Link to a file outside of Context

 
Liming Xu
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all, I'm trying to list a directory's content(includes files and subdirectories). The problem is that I want to make a link to the files say a zip, so that they'll be able to download it.
Now, this directory is not under my web context, in another words, say my web application context is pointed to /usr/local/www/ , but I want to list the directory of /usr/jakarta/ and links to the files underneath it for download.
I have no problem genreate a page for displaying those files listing by use native File Object supplied with "/usr/jarkarta", I just have a problem when i need to make a html link. When I do
<a href="/usr/jakarta/tomcat4.zip"> Tomcat 4 </a>
the weblink interpreted as http://mywebsite/context/usr/jarkarta/tomcat4.zip,
how do I get over this? Again the directory is outside of my context, so getServletContext().getRealpath() doesn't really work for me when comes to make a html link. thanks a LOOTTTT.
Liming
 
Tim Holloway
Bartender
Posts: 18415
58
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's because a web server's not a file server. It might look like one, because of the "index" functionality, but that's just because there are times when it's useful to look like an FTP server. By restricting access to contexts and allowing for security rules within the contexts, the web server is protecting the machine it runs on (and possibly machines it's connected to). Otherwise someone could walk up and down the filesystem and learn places to hack in.
A context looks like a directory tree, and usually maps by default like one, but it's actually a virtual directory tree. In Apache, you could use an Alias directive in the httpd.conf file to do what you wanted. Like this:
Alias /tomcatstuff/ /usr/jakarta/
Which would allow you to see the tomcat4.zip file in your directory on the web at http://yourhost/tomcatstuff/tomcat4.zip
If you're not using a front-end like Apache, or if you're using a "greedy" Apache-to-Tomcat channel like mod_webapp, you'd have to do it Tomcat's way. Since web apps are supposed to be distributable in a single jar file, an out-of-context reference may be hard to set up using a URL mapping the way an Apache Alias directive does. I don't know without re-reading the specs. But in unix-like OS's, you can use a soft link to make the out-of-context directory appear within the context tree like this:
ln -s /usr/jakarta /usr/local/www/tomcatstuff
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!