1. 程式人生 > >tomcat配置預設顯示頁面

tomcat配置預設顯示頁面

所謂的修改tomcat的預設主頁,就是在tomcat伺服器開啟時輸入ip:port能直接進入你自己定義的主頁而不是tomcat主頁,具體有以下幾個步驟:

①首先進入tomcat 下的conf目錄,修改server.xml檔案,具體修改程式碼如下:

<?xml version='1.0' encoding='utf-8'?> <Server port="8005" shutdown="SHUTDOWN">   <Listener className="org.apache.catalina.startup.VersionLoggerListener" />   <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />   <Listener className="org.apache.catalina.core.JasperListener" />   <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />   <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />   <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />

  <GlobalNamingResources>

    <Resource name="UserDatabase" auth="Container"               type="org.apache.catalina.UserDatabase"               description="User database that can be updated and saved"               factory="org.apache.catalina.users.MemoryUserDatabaseFactory"               pathname="conf/tomcat-users.xml" />   </GlobalNamingResources>

  <Service name="Catalina">

    <Connector port="80" protocol="HTTP/1.1"                connectionTimeout="20000"                redirectPort="8443" />

    <Engine name="Catalina" defaultHost="localhost">

      <Realm className="org.apache.catalina.realm.LockOutRealm">         <Realm className="org.apache.catalina.realm.UserDatabaseRealm"                resourceName="UserDatabase"/>       </Realm>

      <Context path="" docBase="/" debug="0"/>        <Host name="你想修改的預設頁面連線(比如:www.xxx.com,前提你得把埠改成80,如果沒改要加上:8080)"  appBase="webapps"             unpackWARs="true" autoDeploy="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 %b" />

      </Host>     </Engine>   </Service> </Server> 如果你還想配置多個預設頁面那麼你得在標籤下加上如下程式碼,配幾個加幾段即可:

 <Context path ="" docBase="/"  debug="0" reload ="true"/>       <Host name="你想修改的預設頁面連線" appBase="webapps1" unpackWARs="true" autpDeploy="true">   </Host> ②如果你要配置多個自定義HOST主頁,複製tomcat目錄下的webapps資料夾,配幾個複製幾個,然後把webapps下的ROOT資料夾清空,把你要配置的預設頁面放進去,上圖如下:

該注意的是清完ROOT下的tomcat自帶頁面和js後,你替代的頁面如果涉及很多js和css可以一併丟上去

然後重啟tomcat就可以看到效果。具體效果如下圖:

③配置web.xml,在tomcat conf 下找到如下程式碼:

<welcome-file-list>         <welcome-file>index.html</welcome-file>         <welcome-file>index.htm</welcome-file>         <welcome-file>index.jsp</welcome-file>     </welcome-file-list> 這個配置檔案是搜尋ROOT或者專案下預設主頁的,預設從index.html開始匹配如果沒匹配到就從index.htm繼續匹配,一般專案的主頁或者預設主頁都是index.jsp or html,如果你的預設主頁是main.jsp或者html只需在這個 標籤裡面加上你自己的主頁名字即可。