Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
624 views
in Technique[技术] by (71.8m points)

configuration - Configure Symlinks for single directory in Tomcat

I have a directory to which a process uploads some .pdf files. This process is out of my control.

I need to make those files available through the website using Tomcat.

I have a directory /var/lib/tomcat5/webapps/test1 available to the web and I can see the files in it with a browser.

So, I created a symbolic link pointing at the directory with the .pdf files: /var/lib/tomcat5/webapps/test1/files/, but I can't see anything in that directory.

How can I enable symlinks in the test1 directory only? I don't want to enable symlinks everywhere, just so that directory with .pdf files is available to the web.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

There are a few problems with the solution of creating a META-INF/context.xml that contains <Context path="/myapp" allowLinking="true">

The biggest issue is that if a conf/context.xml exists, the allowLinking in the <Context> there takes precedence over a <Context> in a META-INF/context.xml. And if the in the conf/context.xml does not explicitly define allowLinking, that's the same as saying allowLinking="false". (see my answer to a context precedence question)

To be sure that your app allows linking, you have to say <Context override="true" allowLinking="true" ...>.

Another issue is that the path="/myapp" is ignored in a META-INF/context.xml. To prevent confusion, it's best to leave it out. The only time path in a <Context> has any effect is in the server.xml, and the official Tomcat docs recommend against putting <Context>s in a server.xml.

Finally, instead of a myapp/META-INF/context.xml file, I recommend using a conf/Catalina/localhost/myapp.xml file. This technique means you can keep the contents of your META-INF clean, which is the guts of your webapp -- I don't like to risk mucking about in the guts of my webapp. :-)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...