1瘦材、servlet.xml中 Context標(biāo)簽下參數(shù)的含義
<Context path="/xxx" docBase="D:\xxx" debug="0" reloadable="true" crossContext="true" />
- path 指出你的訪問路徑
- docBase指出你的存放路徑
- debug 為設(shè)定debug的等級0提供最少的信息,9提供最多的信息
- reloadable=true時 當(dāng)web.xml或者class有改動的時候都會自動重新加載不需要從新啟動服務(wù)(建議正式發(fā)布項目時改為false)
- crosscontext="true"表示配置的不同context共享一個session
2泞边、一個tomcat發(fā)布多個項目
-
發(fā)布不同端口
- 在<Service name="Catalina">...</Service>標(biāo)簽后面添加新的service
并且要重新命名<Service name="Catalina8081">沙咏,<Engine name="Catalina8081" defaultHost="localhost">吐葵,<Host name="localhost" appBase="webapps8081"三處的名字- 在webapps同目錄下新建上一步重命名的文件夾 webapps8081逢慌,
并將原始webapps內(nèi)的所有文件考進去
<Service name="Catalina8081">
<Connector port="8081" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
<Engine name="Catalina8081" defaultHost="localhost">
<Realm className="org.apache.catalina.realm.LockOutRealm">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
</Realm>
<Host name="localhost" appBase="webapps8081"
unpackWARs="true" autoDeploy="true">
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log" suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
</Host>
</Engine>
</Service>
-
發(fā)布相同端口
- 打開server.xml
- 添加如下代碼
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="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 "%r" %s %b" />
<Context path="/XX" docBase="webapps" debug="0" reloadable="true" crossContext="true" />
<Context path="/yy" docBase="webapps8081" debug="0" reloadable="true" crossContext="true" />
</Host>
3妙啃、發(fā)現(xiàn)問題疾党,解決問題
1音诫、比較容易遇到的一個問題,tomcat正常啟動雪位,但是只能打開一個項目竭钝,另一個則報404錯誤
可能的解決方法:
- 通常是log4j或者logback導(dǎo)致的,因為它們保存日志的路徑一樣雹洗,只需要修改路徑
- 修改web.xml文件香罐,添加webAppRootKey
1、例如 logback 修改路徑${catalina.home}為${catalina8081.home}
<appender name="file" class="ch.qos.logback.core.rolling.RollingFileAppender">
<!--See http://logback.qos.ch/manual/appenders.html#RollingFileAppender-->
<!--and http://logback.qos.ch/manual/appenders.html#TimeBasedRollingPolicy-->
<!--for further documentation-->
<file>${catalina8081.home}/logs/example_log/PurePro_</file>
<encoder>
<pattern>[example_sys] %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${catalina8081.home}/logs/example_log/PurePro_.%d{yyyy-MM-dd'.log'}</fileNamePattern>
</rollingPolicy>
</appender>
2时肿、修改web.xml庇茫,在最后加入下面代碼
<context-param>
<param-name>webAppRootKey</param-name>
<param-value>mos_ms.root</param-value>
</context-param>