Serving files from the Tomcat context
I have a web application deployed in Tomcat 6 as a WAR file. Inside the application, I would like to serve files in a directory from this context. For example, I am deploying myapp.war
to /mydir/webapps
, and I access my application via:
http://myhost:myport/myapp/
I would like to serve files via:
http://myhost:myport/myapp/files/somefile.txt
How can i do this? So far, I can serve files outside of the application context:
http://myhost:myport/files/somefile.txt
with files located in /mydir/webapps/files
, not in a directory /mydir/webapps/myapp/files
.
source to share
Use a subcontext pointing to an external directory.
Based on the paths in your example, you want to add the following file: $ CATALINA_BASE / <enginename> / <hostname> /myapp#files.xml (usually $ CATALINA_BASE / Catalina / localhost / myapp # files.xml
with the following content
<Context docBase="/mydir/webapps/files" />
Please note that the / mydir / webapps / files file must be located outside of any HostBase host where autoDeploy is enabled for safe operation.
source to share