tomcat Server.xml Context配置


有時候需要在tomcat里面做特殊的配置,來進行訪問:

 

例如你的程序 名字是hello端口是80  這時候你要訪問你的程序 就要用 localhost/hello 來訪問了。

但是怎么直接用 localhost來訪問呢?就需要進行tomcat 的配置了呢

看以下配置:tomcat里面conf 里的server.xml 最下面

<Host name="localhost"  appBase=""
            unpackWARs="true" autoDeploy="true"
            xmlValidation="false" xmlNamespaceAware="false">


        <!-- 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 -->
        <!--
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"  
               prefix="localhost_access_log." suffix=".txt" pattern="common" resolveHosts="false"/>
        -->
 
<Context docBase="webapps/hello" path="/hello"  reloadable="true" ></Context>
<Context docBase="webapps/hello" path="/"  reloadable="true" ></Context>
                <Context docBase="webapps/cas" path="/cas"  reloadable="true" ></Context>
       </Host>
   這里原來帶有的appBase是有值的 是webapps 這里的意思 是加載webapps下面所有的項目,等於是只要你放到webapp里面的項目都會被加載,(這里我就不寫了 我在下面寫了配置讓他加載)

然后你自己可以寫 context來寫你的項目,docBase可以寫絕對地址也可以寫相對地址,相對地址是相對於你的tomcat來說的,這里 寫為webapps/hello意思就是 webapp下面的 hello;

這里要說一下 啟動的時候加載兩遍的問題 當你appBase里面寫 過webapps 的話 他會先自動加載一所有的然后加載你配置的。所以你不想他加載兩遍 你就可以 在appBase里面什么也不寫。

但是這樣會遇到一個問題,就是 當我用struts跳轉的時候,你發現 不不配置 <Context docBase="webapps/hello" path="/hello"  reloadable="true" ></Context>這個的時候  你的項目會找不到struts的返回頁面,這就是弊端,你想通過不輸入項目名字訪問項目,但是你的程序會找不到result,所以你還得寫上原來的映射,這樣你訪問的首頁是通過<Context docBase="webapps/hello" path="/"  reloadable="true" ></Context>這個訪問的,但是里面的一些跳轉是根據<Context docBase="webapps/hello" path="/hello"  reloadable="true" ></Context>他來跳轉的。所以還是加載了兩遍,。這里要根據你的項目來決定。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM