As mentioned in the previous blog post server.xml configuration, the default mapping path for Tomcat is the host tag
The AppBase property (the application base directory, which is the directory where the application is stored, can be accessed through a URL). So, can I modify the basic directory of this application? Can you point it to my project?
How to configure the Tomcat mapping path
First, the default configuration
Location: Server.xml file in the/conf folder
AppBase: You can specify an absolute directory or a relative directory relative to <CATALINA_HOME>. If this is not the case, the default is <catalina_home>/webapps.
The default root directory is defined as "WebApps" (relative path, relative to <CATALINA_HOME>)
Second, add <Context> label
Location: Server.xml file in the/conf folder
You can create custom access by adding multiple context tags under the host tag. Generally we use the context to override the host's appbase setting instead of modifying the appbase directly.
eg
<context path= "" docbase= "ROOT" debug= "0"/>
<context path= "/sample" docbase= "sample" debug= "0" reloadbale= "true"/>
<context path= "" docbase= "D:\JavaWork\servlet\servlet" debug= "0" reloadbale= "true"/>
Virtual directory for Path:host
DocBase: The address of the mapped physical directory, the relative path can be specified, and the absolute path (for example: D:\Workes\testtomcat\WebRoot) can be specified relative to appbase. If this is not the default is Appbase/root.
Context One:
Path= "" (Note not path= "/") is equivalent to the virtual root of this host, Docbase indicates that the location of the physical directory is relative to the root directory under AppBase. So when you enter http://localhost:8080/in the browser, you are accessing the root directory under WebApps.
Context II:
If you visit http://localhost:8080/sample/, you will get access to the content in Appbase/sample.
Context III:
Path= "" means that this is the virtual root of host, and Docbase indicates that the physical directory is an absolute address, because if you access http://localhost:8080/, you will be accessing D:javawork/servlet/servlet In the content.
Iii. writing an XML file
Location: Under the conf/catalina/localhost/directory
For the tomcat5.x version, you can map it by writing an XML file in the conf/catalina/localhost/directory, where the <Context> element is set. However, this is done by using the name of the current XML file as a virtual subdirectory, rather than by path.
PS. This method requires a restart of the server.
Eg: add Myapp.xml
<?xml version= ' 1.0 ' encoding= ' utf-8 '?>
<context path= "/myapp" docbase= "Project Address" debug= "0" reloadbale= "true" >
XML file name: Virtual directory for Host
DocBase: The absolute address of the physical directory.
After restarting the server, the http://localhost:8080/myapp/will be mapped to the "Project address" path.
How to configure the Tomcat mapping path (application base directory)