<span id="Label3"></p><strong>Let's start with a look at the <strong>web's virtual directory Mapping and host building knowledge</strong></strong><p><p><br></p></p><strong><strong>first: Virtual directory Mapping of the Web</strong></strong><p><p>First of all, we need to know what is called the Web virtual directory mapping, which is very well understood, is to map our local hard disk Web application to an external user access to the address directory process is called directory mapping, for Example: I have now developed a Web application demo, stored under my c disk, But I want to give the user access to my web resources, so to provide the user with an address directory: called/demo, so that users can enter in the address Bar: http://localhost:8080/Demo/ Index.html can access the homepage of my web App (assuming the home page in the Web app is index.html). But how does this directory map? Let's take a couple of approaches to This:</p></p><p><p><br></p></p><p><p><strong>First Method: Modify the Server.xml file</strong></p></p><p><p>Go to the root directory of the Tomcat server, go to the Conf directory, Locate the Server.xml file, we find the host tag, and then add the following code below the Tag:</p></p><span><span>?</span></span> <table border="0" cellpadding="0" cellspacing="0"> <tbody> <tr> <td class="gutter">1</td> <td class="code"><code class="java plain"><context path=</code><code class="java string">"/Demo"</code><code class="java plain">docbase=</code><code class="java string">"C:\Demo"</code><code class="java plain">></context></code></td> </tr> </tbody> </table><p><p>This maps the Demo application in the local c-drive directory To/demo so that outside users can access my web app.</p></p><p><p><strong>Note: You must remember to restart Tomcat after modifying the Server.xml file, otherwise it will not have any effect</strong></p></p><p><p><strong><br></strong></p></p><p><p>The disadvantage of this method is to restart the Tomcat server after each modification, this is a very painful thing, because restarting the Tomcat server will affect the current user is being accessed, it will cause a poor user experience, so this method is not recommended for Use.</p></p><p><p><br></p></p><strong><strong>Second method: Add an XML file</strong></strong><p><p>Go to the root directory of Tomcat and then go to the Conf/catalina/localhost directory and create a new Demo.xml file in the directory: enter the Content:</p></p><span><span>?</span></span> <table border="0" cellpadding="0" cellspacing="0"> <tbody> <tr> <td class="gutter">1</td> <td class="code"><code class="java plain"><context docbase=</code><code class="java string">"C:\Demo"</code><code class="java plain">></context></code></td> </tr> </tbody> </table><p><p>After saving the file, you can access http://localhost:8080/Demo/index.html without restarting the Server. What is the principle here?</p></p><p><p>In fact, we see the input content and the first method of the input content is a little different that is not the path property, this is why? In fact, because path is the corresponding virtual directory, but now the XML file name is Demo.xml so, This property can not be Required. Here you need to say the name of the XML file naming Rules.</p></p><p><p>The name of this file must be the name of the mapping directory. If it is a multilevel mapping directory, use: "#" to connect between:</p></p><p><p>The mapping directory is:/demo/foo/download then his corresponding XML file name is demo#foo#download, this is very simple. And compared with the first method, this method does not need to restart the server, so this method is Recommended.</p></p><p><p><br></p></p><p><p>In fact, there are other ways of configuring the virtual directory, and we can look at the Tomcat documentation:</p></p><p><p>http://localhost:8080 into Tomcat Home</p></p><p><p>Locate the Tomcat documentation->reference->configuration->containers->context, if shown:</p></p><p><p><br></p></p><p><p>From the above can see a total of five ways to realize the virtual directory mapping, but also noted that we talked about the first method, the official document suggested that we do not use, is the figure of the 5th, and we are talking about the second method is the 3rd, as for the other three mapping methods, here do not introduce, Interested students can study on their own, personal feelings, there is no need to master so many ways, as long as there are one or two kinds on it, so many methods can not actually use.</p></p><p><p><br></p></p>Here is a look at the knowledge of the host building<p><p>First look at the demand, now we want to enter in the address Bar: http://www.google.com:8080/Demo/index.html can access our web App</p></p><p><p>Here we can see that the previous is http://localhost:8080/Demo/index.html access, so we need to build a www.google.com host Here.</p></p><p><p>Enter the Server.xml file, find the host node, of course, there can be more than one host node, because one hosts node corresponding to one, so we add a host hosts Can:</p></p><p><p><br></p></p><p><p>Here the name is the hostname, and AppBase is the Web application directory accessed under that Host. This is the localhost, so we put the app in the WebApps directory and we have access to our app.</p></p><span><span>?</span></span> <table border="0" cellpadding="0" cellspacing="0"> <tbody> <tr> <td class="gutter">12</td> <td class="code"><code class="java plain">
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.