//Note: $CATALINA_BASE represents the directory where Tomcat is installed, you will see later
// the first half is for analysis, and the second half is for actual combat
//CATALINA --> a nice name: Catalina
What is the deployment of web applications and the mapping of website directories? To put it bluntly, it is how to allow users to access the websites we develop.
As we all know, our websites are placed in a certain file on a certain hard disk of a certain server.
For example, I developed a website and put it under the E:\MyWeb folder of the XXX server
Now I want others to visit my website, what should I do?
Detailed instructions are given in the help documentation of Tomcat 6.0.36,
After installing Tomcat, open the following address and you can see the document
http://localhost:8080/docs/config/context.html
//About how to deploy web applications and map website directories, Tomcat's original text is as follows
For Tomcat 6, unlike Tomcat 4.x, it is NOT recommended to place <Context> elements directly in the server.xml file. This is because it makes modifying theContext configuration more invasive since the mainconf/server.xml
file cannot be reloaded without restarting Tomcat.
Context elements may be explicitly defined:
- 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. - In individual files (with a ".xml" extension) in the
$CATALINA_BASE/conf/[enginename]/[hostname]/
directory. The name of the file (less the .xml extension) will be used as the context path. Multi-level context paths may be defined using #, e.g.foo#bar.xml
for a context path of/foo/bar
. The default web application may be defined by using a file calledROOT.xml
. - Only if a context file does not exist for the application in the
$CATALINA_BASE/conf/[enginename]/[hostname]/
, in an individual file at/META-INF/context.xml
inside the application files. If the web application is packaged as a WAR then/META-INF/context.xml
will be copied to$CATALINA_BASE/conf/[enginename]/[hostname]/
and renamed to match the application's context path. Once this file exists, it will not be replaced if a new WAR with a newer/META-INF/context.xml
is placed in the host's appBase. - Inside a Host element in the main
conf/server.xml
.
With the exception of server.xml, files that define Context elements may only define a singleContext element.
//It can be seen from the above that Tomcat has given 5 methods for us to configure web applications. Here I am talking about the third one.
//Simple and practical, no need to restart Tomcat
//The original translation is as follows
//In the archive file with the extension .xml, it is the xml file
In individual files (with a ".xml" extension)
//The localhost folder in the Tomcat installation directory
//For example, mine is D:\Tomcat\Tomcat6.0.36\conf\Catalina\localhost
in the $CATALINA_BASE/conf/[enginename]/[hostname]/ directory.
//The file name removes the .xml suffix and will be used as the path of the web application
//What is the context path? For example, if my localhost file is ok.xml, then ok is the context path.//The
user opens the web page in the form of http:/ /XXX:8080/ok/123.html
//Note: ok.xml has a path of 123.html, such as <context docBase="E:\Web"/>
//E:\Web contains 123. html
The name of the file (less the .xml extension) will be used as the context path.
//Multi-level road strength is defined by #, and the file name is in the form of aaa#bbb#ccc.xml
//The access form is http://XXX:8080/aaa/bbb/ccc/123.html
Multi-level context paths may be defined using #,
eg foo#bar.xml for a context path of /foo/bar.
//Define the default web application and create a ROOT.xml file.//Don't
forget to set the path of the website in ROOT.xml
The default web application may be defined by using a file called ROOT.xml.
// combat part
1) The webpage I tested is placed under E:\MyWeb, the screenshot is as follows
2) Tomcat is installed in D:\Tomcat\Tomcat6.0.36 The screenshot is as follows
3) Enter the localhost directory D:\Tomcat\Tomcat6.0.36\conf\Catalina\localhost
//Create a file ok.xml in the localhost directory with the content <Context docBase="E:\MyWeb"/>
//The screenshot is as follows
4) Start Tomcat and visit http://localhost:8080/ok/ hello.html
/// Attach-->A simple way to access web applications
//Copy the entire directory of our web application to the webapps folder in the Tomcat installation directory
//For example, copy MyWeb to webapps
// Then start Tomcat can access http://localhost:8080/MyWeb/hello.html
REFS:http://blog.csdn.net/friendan/article/details/8116743