直接在server.xml中<Host></Host>间加了一句<Context path="" docBase="/springmvc" debug="0" reloadable="true"/>,其中docBase="/springmvc"中的/fts是项目名字


把项目放到tomcat6\webapps下面

修改Host


<Host name="www.test.com"  debug="0" appBase="webapps" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false">

<Context path="/" docBase="/test"  debug="0" reloadable="true"></Context>

</Host>

这样就可以通过域名www.test.com访问test为项目名的项目了。



如果主机中绑定多个域名,直接加host即可

eg.在hosts文件中:

127.0.0.1 test.springmvc.com

127.0.0.1 test.mall.com


在server.xml中

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<Host name="test.springmvc.com"  appBase="webapps"
      unpackWARs="true" autoDeploy="true">
  <!-- 去掉项目名称 -->
  <Context path="" docBase="/springmvc" debug="0" reloadable="true"/>
                                                                       
                                                                       
  <!-- SingleSignOn valve, share authentication between web applications
       Documentation at: /docs/config/valve.html -->
  <!--
  <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
  -->
  <!-- Access log processes all example.
       Documentation at: /docs/config/valve.html
       Note: The pattern used is equivalent to using pattern="common" -->
  <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
         prefix="localhost_access_log." suffix=".txt"
         pattern="%h %l %u %t &quot;%r&quot; %s %b" resolveHosts="false"/>
</Host>
<Host name="test.mall.com"  appBase="webapps"
      unpackWARs="true" autoDeploy="true">
  <!-- 去掉项目名称 -->
  <Context path="" docBase="/mall" debug="0" reloadable="true"/>
                                                                       
                                                                       
  <!-- SingleSignOn valve, share authentication between web applications
       Documentation at: /docs/config/valve.html -->
  <!--
  <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
  -->
  <!-- Access log processes all example.
       Documentation at: /docs/config/valve.html
       Note: The pattern used is equivalent to using pattern="common" -->
  <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
         prefix="localhost_access_log." suffix=".txt"
         pattern="%h %l %u %t &quot;%r&quot; %s %b" resolveHosts="false"/>
</Host>

说明:

<Host name="localhost"  appBase="D:\appBase\"
           unpackWARs="true" autoDeploy="true"
           xmlValidation="false" xmlNamespaceAware="false">
  <Context path="" docBase="E:\Devolope\WebRoot"workDir="D:\appBaseRoot\"  />
</Host>

appBase代表应用的基础目录,原始默认位置为“webapps”即对应于tomcat根目录下的文件夹webapps;

docBase相当于指定的虚拟目录对应的应用程序的绝对路径;workDir是运行编译成为java二进制代码时候存放的目录。


tomcat/conf/server.xml 中docBase="webapps/mall"【这样写可以防止项目加载2次】

1
2
3
4
5
6
7
8
<!-- 2014-04-28-han-add just for mall test -->
  <Host name="mall.kongzhong.com" appBase="" unpackWARS="true" autoDelpoy="true">
  <Context path="" docBase="webapps/mall" debug="0" reloadable="true" useHttpOnly="true"/>
   <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
                  prefix="localhost_access_log." suffix=".txt"
                                 pattern="%h %l %u %t &quot;%r&quot; %s %D %b" />
                                                     
</Host>