Tomcat Configuring Web virtual maps and configuring virtual hosts

Source: Internet
Author: User

Tomcat Configuring Web virtual maps and configuring virtual hosts

There are three ways to configure the Web Virtual Map folder, such as the following:

First ( to restart the server ):

Open the Server.xml file under the path Tomcat 6.0\conf,

Add a line above the </Host> of the file content? A statement : <context path= "" docbase= "here point to the folder you want to map for example (E:\code\news)" reloadable= "true"/ >, Notice the changes to restart the server and then visit http://localhost:8000/test.html in the browser (test.html is the file stored in the E:\code\news folder, If you change to path path= "/hello", then visit http://localhost:8000/hello/test.html on your browser.


Note : Let's say path= "/hello" note to have a backslash '/'

reloadable= "true" after the source program to save a bit, and actively restart the server, and change the JSP file, do not need to restart the server


Second ( no need to restart the server):

create an XML file under the folder path: \tomcat 6.0\conf\catalina\localhost (for example,

A.xml) file contents: <context docbase= "Here point to the folder you want to map for example (E:\code\news

) "/> Then visit the browser http://localhost:8000/a/test.html
Note : test.html is a file stored in the E:\code\news folder;
Assuming that the Catalina directory cannot be found under the Conf directory, copy the Catalina directory under \tomcat 6.0\work to the \tomcat 6.0\conf file.

Third (throw the folder folder directly under the WebApps folder, which is also the simplest, without restarting the server):

Method 1. Throw the folder folder directly under the WebApps folder

Method 2. Packaging the directory into a war file is still in the WebApps directory, this is very convenient, in such a way to send the file to the customer is also common, the directory is packaged into a war file : First open the directory path you want to package in the DOC environment analogy: note the last other point "."

To configure a virtual host:

If you want to configure a virtual host on your computer for example: www.google.com;

You can access your local server's resources by entering www.google.com in your browser.

actions such as the following :

If you create a Google directory on the E drive and there is a new1 directory, New1 directory has a a.html file and a web-inf directory, the Web-inf directory has a Web. xml file ( This file is a.html as the home page ),

The contents of the Web. xml file are:

[HTML]View Plaincopy
  1. <? XML version="1.0" encoding="iso-8859-1" ?>   
  2. < Web-app xmlns="Http://java.sun.com/xml/ns/javaee"
  3. Xmlns:xsi = "Http://www.w3.org/2001/XMLSchema-instance"   
  4. xsi:schemalocation = "Http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"   
  5. version = "2.5" >   
  6. < welcome-file-list >   
  7. < Welcome-file > a.html </ Welcome-file >   
  8. </ welcome-file-list >   
  9. </ Web-app >   


In fact, this file is the end of the Web. xml file in the Tomcat 6.0\conf folder .

then, in the Tomcat 6.0\conf folder, add the Server.xml file to this program, which is placed on top of </Engine> ; Remember to change the port number 8080 into a server.xml file:

[HTML]View Plaincopy
  1. < Host name="www.google.com" appBase=" E:\google " >
  2. < Context path="" docBase="E:\google\news1" />
  3. </ Host >   

And then add it in the Hosts file? IP and www.google.com of the host

Hosts file under the C:\WINDOWS\system32\drivers\etc folder, the host's IP generally you open the Hosts file there will be displayed, for example: 127.0.0.1 www.google.com

Finally, visit www.google.com on the browser to see the contents of the a.html file. ( Note To restart the server)



Tomcat Configuring Web virtual maps and configuring virtual hosts

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.