Configure web virtual ing for Tomcat and configure Virtual Hosts
There are three methods to configure the WEB virtual ing directory:
First (to restart the server ):
Open the server. xml file under Tomcat 6.0 \ conf,
Add a statement in the preceding line of (Test.html) is a file stored in the E: \ code \ news directory. If it is changed to Path = "/Hello", access http: // localhost in the browser: 8000/Hello/test.html.
Note:For examplePath = "/hello"
Note that there must be a backslash '/'
Reloadable = "true" after modifying the source program, save it and automatically restart the server. However, if you modify the JSP file, you do not need to restart the server.
Second (no need to restart the server ):
Create an XML file in the directory \ Tomcat 6.0 \ conf \ Catalina \ localhost (for example
A. XML) file content: <context docbase = "this point points to the directory you want to map, such as (E: \ code \ news
) "/> Access http: // localhost: 8000/A/test.html in the browser.
Note: test.html is a file stored in the E: \ code \ news directory;
If the Catalina folder cannot be found in the conf folder, copy the Catalina folder under \ Tomcat 6.0 \ work to the \ Tomcat 6.0 \ conf file.
Third (it is also the easiest to directly drop the directory folder to the webapps directory without restarting the server ):
Method 1. Directly drop the directory folder into the webapps directory
Method 2. it is convenient to package folders into war files in the webapps directory. It is also common to send files to customers in this way. You can package folders into war files: first, open the folder path you want to package in the doc Environment
For example, pay attention to the last point ".".
Configure the VM:
Suppose you want to configure a virtual host on your computer, for example, www.google.com;
Enter www.google.com in a browser to access the resources on your local server,
The procedure is as follows:
Suppose you create a Google folder on the drive with a new1 folder, The new1 folder contains an a.html file and a WEB-INF folder, and the WEB-INF folder contains a web.xmlfile (this file uses a.html as the home page ),
The content in the web. xml file is:
[HTML]
View plaincopy
- <? XML version = "1.0" encoding = "ISO-8859-1"?>
- <Web-app xmlns = "http://java.sun.com/xml/ns/javaee"
- Xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance"
- Xsi: schemalocation = "http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
- Version = "2.5">
- <Welcome-file-List>
- <Welcome-File> a.html </welcome-File>
- </Welcome-file-List>
- </Web-app>
In fact, this file is the beginning and end of the web. xml file under the Tomcat 6.0 \ conf directory.
Then, in the Tomcat 6.0 \ conf directory, the server. add such a program to the XML file. Put this statement on the </engine>. Remember to add the program to the server. in the XML file, replace port 8080 with 80:
[HTML]
View plaincopy
- <Host name = "www.google.com" appbase = "E: \ google">
- <Context Path = "" docbase = "E: \ google \ news1"/>
- </Host>
Then add the Host IP address and
Www.google.com
The hosts file is in the c: \ windows \ system32 \ drivers \ etc directory. The host IP address is usually displayed when you open the hosts file, for example, 127.0.0.1 www.google.com.
Finally, access www.google.com in a browser to view the contents of the.html file. (Restart the server)