Web应用虚拟目录的映射的几种方式
It is NOT recommended to place <Context> elements directly in the server.xml file. This is because it makes modifying the Context configuration more invasive since the main
conf/server.xml
file cannot be reloaded without restarting Tomcat.不建议放在server.xml中增加节点,需要重启
Individual Context elements may be explicitly defined:
- In an individual file at
/META-INF/context.xml
inside the application files. In Tomcat 6 this file is automatically copied to$CATALINA_BASE/conf/[enginename]/[hostname]/
and renamed to application's base file name plus a ".xml" extension. (This automated copying became optional in Tomcat 7).- META-INF / context.xml里面被共享
- In individual files (with a ".xml" extension) in the
$CATALINA_BASE/conf/[enginename]/[hostname]/
directory. The context path will be derived from the base name of the file (the file name less the .xml extension). This file will always take precedence over any context.xml file packaged in the web application's META-INF directory.- 映射成xml文件出去前缀的地址,ROOT.xml,缺省,需要重启
- Inside a Host element in the main
conf/server.xml
.Default Context elements may be defined that apply to multiple web applications. Configuration for an individual web application will override anything configured in one of these defaults. Any nested elements, e.g. <Resource> elements, that are defined in a default Context will be created once for each Context to which the default applies. They will not be shared between Context elements.
- In the
$CATALINA_BASE/conf/context.xml
file: the Context element information will be loaded by all web applications.- In the
$CATALINA_BASE/conf/[enginename]/[hostname]/context.xml.default
file: the Context element information will be loaded by all web applications of that host.With the exception of server.xml, files that define Context elements may only define a single Context element.
In addition to explicitly specified Context elements, there are several techniques by which Context elements can be created automatically for you. See Automatic Application Deployment and User Web Applications for more information.
To define multiple contexts that use a single WAR file or directory, use one of the options described in the Naming section above for creating a Context that has a path that is not related to the base file name.