2、重复步骤一再次创建一个Service
<Servicename="Catalina.app2">
<Connector port="8082"protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443"/>
<EngineCOLOR: red">Catalina.app2" defaultHost="localhost">
<RealmclassName="org.apache.catalina.realm.LockOutRealm">
<RealmclassName="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
</Realm>
<HostCOLOR: red">localhost" appBase="webapps"
unpackWARs="true"autoDeploy="true">
<ValveclassName="org.apache.catalina.valves.AccessLogValve"directory="logs"
prefix="localhost_access_log."suffix=".txt"
pattern="%h %l %u %t"%r" %s %b" />
<Context path="/"docBase="app2" />
</Host>
</Engine>
</Service>
3、启动Tomcat,观察日志输出
信息: Deploying webapplication directory E:\WorkSpace\JavaWorkspace\Tomcat 7.0\webapps\app1
2012-6-414:03:36 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: Parsingconfiguration file [struts-default.xml]
2012-6-414:03:37 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: Parsingconfiguration file [struts-plugin.xml]
2012-6-414:03:37 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: Parsingconfiguration file [struts.xml]
2012-6-414:03:38 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deploying webapplication directory E:\WorkSpace\JavaWorkspace\Tomcat 7.0\webapps\app2
2012-6-414:03:39 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: Parsingconfiguration file [struts-default.xml]
2012-6-414:03:39 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: Parsingconfiguration file [struts-plugin.xml]
2012-6-414:03:39 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: Parsingconfiguration file [struts.xml]
4、通过浏览器访问:
:80801/index.jsp
我们通过观察浏览器发出的请求头如下:
Request URL: :8081/index.jsp
Request Method:GET
Status Code:200 OK
Request Headersview source
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Charset:GBK,utf-8;q=0.7,*;q=0.3
Accept-Encoding:gzip,deflate,sdch
Accept-Language:zh-CN,zh;q=0.8
Cache-Control:max-age=0
Connection:keep-alive
Cookie:JSESSIONID=CADAAC6E5B9366F4590E50B889BE58BF
Host:localhost:8081
Pragma:no-cache
User-Agent:Mozilla/5.0 (Windows NT 5.1)AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.168 Safari/535.19 QIHU360EE
Response Headersview source
Content-Length:1235
Content-Type:text/html;charset=UTF-8
Date:Mon, 04 Jun 2012 06:24:19 GMT
Server:Apache-Coyote/1.1
Set-Cookie:JSESSIONID=BA86EAD5BBDF7BB51343377C88588AB8;Path=/; HttpOnly
请注意红色的部分就是主机头,一般是Internet域名。
localhost:80802/ognl.jsp
这里和上面做法一样,主机头是:Host:localhost:8082
5、观察Tomcat的conf目录:
你发现了什么?????????????????????????????????????
Catalina.app1和Catalina.app2是我们分别配置的两个Engine的名字。打开这两个目录,我们发现:
里面都有个localhost,其实这是我们上面配置的虚拟主机名称,如果你配置的虚拟主机名称是qrkx.uten.cn,那么这里目录的名称就是qrkx.uten.cn了。
注意:如果你的Webapps目录下有ROOT目录请将其更名或删除,否则访问地址::8081和:8082是会出问题的。官方文档有这样的说明:If the contextPath is a zero length string, the base name isROOT