参考:
测试步骤:
1. 修改 C:\WINDOWS\system32\drivers\etc\hosts ,追加以下两行:
- 127.0.0.1 mp3.com
-
127.0.0.1 mp4.com
2. 修改 ${CATALINA_HOME}/conf/server.xml 追加以下两个 virtual host
- <?xml version='1.0' encoding='utf-8'?>
-
<Server port="8005" shutdown="SHUTDOWN">
-
...
-
<Service name="Catalina">
-
...
-
<Engine name="Catalina" defaultHost="localhost">
-
...
-
<Host name="mp3.com" appBase="webapps-mp3"
-
unpackWARs="true" autoDeploy="true"
-
xmlValidation="false" xmlNamespaceAware="false" />
-
<Host name="mp4.com" appBase="webapps-mp4"
-
unpackWARs="true" autoDeploy="true"
-
xmlValidation="false" xmlNamespaceAware="false" />
-
...
-
</Engine>
-
</Service>
-
</Server>
3. 创建目录${CATALINA_HOME}/webapps-mp3
创建${CATALINA_HOME}/webapps-mp3/ROOT/index.jsp
- <%@ page contentType="text/html; charset=GBK"%>
-
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
-
<html>
-
<head>
-
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
-
<title>test tomcat cluster : Page B</title>
-
</head>
-
<body>
-
<div>this is a test page</div>
-
<div>cur path = [<%=request.getRealPath(".") %>]</div>
-
</body>
-
</html>
创建${CATALINA_HOME}/webapps-mp3/ROOT/WEB-INF/web.xml
- <?xml version="1.0" encoding="ISO-8859-1"?>
-
<web-app xmlns=""
-
xmlns:xsi=""
-
xsi:schemaLocation=" /web-app_2_5.xsd"
-
version="2.5">
-
-
<welcome-file-list>
-
<welcome-file>index.jsp</welcome-file>
-
</welcome-file-list>
-
</web-app>
4. 启动tomcat
5. 访问 输出以下信息:
- this is a test page
-
cur path = [E:\apache-tomcat-6.0.29-VH\webapps-mp3\ROOT\.]
访问 输出以下信息:
- this is a test page
-
cur path = [E:\apache-tomcat-6.0.29-VH\webapps-mp4\ROOT\.]
Over~~~~, 通过不同的域名,访问不同的目录。
阅读(1097) | 评论(0) | 转发(0) |