Tomcat 映射虚拟目录

①在server.xml中添加如下蓝色代码:

 <Context path="/me" docBase="F:a" />

</Host>

还有一个属性reloadable="true",设成true,web应用一旦更改服务器就会自动加载,不需重启服务器。

然后重启Tomcat,则可以直接访问:http://localhost:8080/me/1.html 来访问F:a文件夹下的文件1.html。

在F:Tomcat 7.0confcontext.xml中配置则可以被所有web应用共享。

原文:In the $CATALINA_BASE/conf/context.xml file: the Context element information will be loaded by all webapps.

②在$CATALINA_BASE/conf/[enginename]/[hostname]/  也就是 F:Tomcat 7.0confCatalinalocalhost 下添加新文件:bbb.xml 置入以下内容

<?xml version="1.0" encoding="UTF-8" ?>
<Context docBase="F:a" />

则可以通过http://localhost:8080/bbb/1.html来访问F:a文件夹下的文件1.html。此方法不需要重启Tomcat。

 ③将方法②中的bbb.xml改名为ROOT.xml

则可以通过http://localhost:8080/1.html来访问F:a文件夹下的文件1.html。此方法需要重启Tomcat。

④将方法②中bbb.xml改名为A#B#C.xml

 则可以通过http://localhost:8080/A/B/C/1.html来访问F:a文件夹下的文件1.html。此方法不需要重启Tomcat。

测试以上内容的时候请注意随时清IE缓存。

原文:

打开Tomcat,访问http://localhost:8080/docs/config/context.html

内容:

Defining a context

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.

Individual Context elements may be explicitly defined:

  • In an individual file at /META-INF/context.xml inside the application files. Optionally (based on the Host's copyXML attribute) this may be copied to $CATALINA_BASE/conf/[enginename]/[hostname]/ and renamed to application's base file name plus a ".xml" extension.
  • In individual files (with a ".xml" extension) in the $CATALINA_BASE/conf/[enginename]/[hostname]/ directory. The context path and version 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.
  • 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 webapps.
  • In the $CATALINA_BASE/conf/[enginename]/[hostname]/context.xml.default file: the Context element information will be loaded by all webapps 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 above for creating a Context that has a path that is not related to the base file name and create multiple Context definitions.

原文地址:https://www.cnblogs.com/flying607/p/3446024.html