Tomcat Context Configuration

Source: Internet
Author: User

Attributes of the <Context> element:
Path: Specifies the URL entry to access the Web App.
DocBase: Specifies the file path of the Web app, either given an absolute path, or a relative path to the AppBase property relative to <Host>, if the Web App takes an open directory structure, specifies the Web app's root directory, if the Web App is a war file, Specifies the path to the war file. (Specify Project site)
Reloadable: If this property is set to true,tomcat the server will monitor changes in the class file under the Web-inf/classes and Web-inf/lib directories, if a class file is monitored, The server will automatically reload the Web App.

After the default installation, Tomcat's home directory is the Webapps/root directory and can do this if we want to change the Tomcat home directory:

1. Open C:/tomcat/conf/server.xml and add code between

<context path= "" docbase= "E:/tomcatapp/jeasycms" debug= "0" reloadable= "true" crosscontext= "true"/>

This restarts Tomcat, and our home directory is set to jeasycms the project. 2. Tomcat will generate a c:/tomcat/conf/catalina/localhost directory, which automatically generates a root.xml (root capitalization) file, which we can see in the Open file:

<?xml version= ' 1.0 ' encoding= ' utf-8 '?>
<context crosscontext= "true" docbase= "E:/tomcatapp/jeasycms" path= "" reloadable= "true" >
</Context> 3. Note: The same is true when we create a virtual directory, except that the path property of the Context tag is not empty. 4. We set up the virtual directory and the home directory, will generate the corresponding XML file in the C:/tomcat/conf/catalina/localhost directory, therefore, When we delete the home directory and the virtual directory settings in the Server.xml, if the system has not yet taken effect, then we have to check if the XML file in this directory has been deleted, if not deleted, he still works on Tomcat, we must manually delete. 5. Based on the 4th, passing the test I found that whenever we visit an address, Tomcat first goes to the C:/tomcat/conf/catalina/localhost directory to see if there is an XML file that has a home directory or virtual directory, and if there is an XML file, Access by the path in the XML, if there is no XML file, go to the Server.xml file to see if the context tag is configured, if the context tag is configured, then the c:/tomcat/conf/catalina/ localhost directory to generate a corresponding XML file, so that the next direct authentication and no longer access to server.xml, while opening the specified path in the context, if there is no context tag configured in Server.xml, then return to the Access error page. 6. Based on the 5th, we can actually create an XML file directly under C:/tomcat/conf/catalina/localhost for the home directory or the virtual directory, Instead of having to modify server.xml to achieve the purpose of configuring the home directory and the virtual directory, the format of the specific XML can be as follows:

<?xml version= ' 1.0 ' encoding= ' utf-8 '?>
<context crosscontext= "true" docbase= "E:/tomcatapp/jeasycms" path= "" reloadable= "true" >
</Context>

Whether the configuration of the home directory or the configuration of the virtual directory depends on the value of path. In addition, the home directory filename must be root.xml (root capitalization), and the virtual directory's file name and virtual directory name are consistent and lowercase, for example: <?xml version= ' 1.0 ' encoding= ' utf-8 '?>
<context crosscontext= "true" docbase= "E:/tomcatapp/jeasycms" path= "/cms" reloadable= "true" >
</Context>

The above defines a virtual directory named CMS and saves the above text as a cms.xml file.

7. When the above living directory is configured, you can access it at the following address:

http://localhost:8080/(Access home directory)

Http://localhost:8080/cms (access to a virtual directory named CMS)

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.