How to configure the Tomcat mapping path (application base directory)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.