Explain how Tomcat sets up virtual paths and why virtual paths are set

Source: Internet
Author: User
Tags tomcat tomcat server


Description: This time using Tomcat 7.0


A lot of friends will be wondering, since we all know that deploying a project on a tomcat server simply packs the project and puts it in the WebApps directory, and why you need to configure the virtual path. Indeed, it is very handy to put items in the WebApps directory, at least when you deploy a project, it is much easier to throw items directly into the WebApps directory than to set up a virtual path. But if you take into account long-term operations and multiple projects.

To set the advantages of a virtual path I've summed up two points, of course, this is a common, very common two points advantage: first, we develop a project, in the undecided version of the need to make countless changes, if the deployment of test projects directly to the project into the war package into the WebApps directory, Then each version change will need to put the new version in the WebApps directory to overwrite the original version, so for us to test the project is not very troublesome. If you create a virtual path and map directly to the original project, this is not very convenient in the testing phase. (This is, of course, negligible for developers using integrated development environment tools); second, Tomcat is a server, since it is a server is not the capacity to say it. Although this capacity is your decision, but no matter how big is also a disk capacity limit. If all the projects are deployed to the WebApps directory, when the project is larger and more projects will need to consider the feeling of the letter. Therefore, you can also use virtual paths to separate the disk characters that carry the Tomcat server.


============== It's really just a split line ==============

Well, the nonsense will not say more, directly cut to the chase.

How do I set up a virtual path? There are a lot of posts on the Internet, but many of them only refer to the 2-3 method, in fact, in the official document of the TOMCAT7 to give 5 sets of methods, let's take a look at 4 of them, because there is a really is not commonly used:


Method 1 (Modify configuration file): This is the most common method

Locate the Conf directory under the TOMCAT7 installation directory, where there is a server.xml file with the task of configuring the entire server information. For example, modify port number, add virtual host ... Open this file, locate the host tag,


In this tab, insert the following code:

<context path= "/yang" docbase= "F:\mysite1\xxx.war" debug= "0" reloadable= "true" crosscontext= "true"/>

Description
Path: Specifies the URL portal to access the WEB application. DocBase: Specifies the file path for the Web application, given an absolute path, or a relative path to the AppBase property of the <Host>, if the Web application uses an Open directory structure, specifies the root directory of the Web application, if the Web application is a war file, Specifies the path of the war file. (Specify the location of the project) Reloadable: If this property is set to true,tomcat the server will monitor changes to class files in web-inf/classes and Web-inf/lib directories if the class is monitored File is updated, the server automatically reloads the WEB application. Crosscontext: Set to True if you want to call Servletcontext.getcontext () within the application to return to the request dispatcher of another Web application running on that virtual host. Set to False in an environment where security is important, so that getcontext () always returns NULL. The default value is False. Debug: The level of detail of the debug information that is associated with this Engine Logger record. The larger the number, the more verbose the output. If not specified, the default is 0.

This method typically requires a reboot of the server after Setup (sometimes a reboot is required even if reloadable= "true" is set)


--------------------------------------------------------------------------------------------------------------- --------------------------------


Method 2 (Add profile): Recommended use, no need to reboot the server

Create a new filename.xml under the/conf/catalina/localhost/path under the Tomcat root and write statements in the XML

<context docbase= "F:\Java\JavaWebWorkspace\news"/>

You can create a virtual site with a virtual site named filename. Note that docbase points to your own application directory, each parameter refer to the parameters of the <Context> tag in Method 1 (note that this file name is the value of the path attribute in the context, regardless of how the Path property value is set in the file is not valid).

If you need a layered virtual site, you can change the file name to a#b#c and access the layered virtual site with localhost:8080/a/b/c

--------------------------------------------------------------------------------------------------------------- -------------------------------

Method 3:

Insert in the Conf directory context.xml file under the Tomcat root directory

<context path= "/zhang" docbase= "f:\mysite1" debug= "0" reloadable= "true" crosscontext= "true"/>

Note that this virtual path modification method will allow all sites to load, Https://localhost:8080/zhang

It is a good idea to open the list settings in Service.xml before using this. --------------------------------------------------------------------------------------------------------------- --------------------------------

Method 4:

The path/conf/catalina/localhost/context.xml.default in the Tomcat root directory is configured here, and this virtual path modification method will allow all sites under that host to load, ditto.





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.