所谓的修改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 "%r" %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只需在这个 标签里面加上你自己的主页名字即可。