900字范文,内容丰富有趣,生活中的好帮手!
900字范文 > 如何更换Tomcat默认主页

如何更换Tomcat默认主页

时间:2019-01-20 17:59:35

相关推荐

如何更换Tomcat默认主页

前言:

安装好tomcat以后,我们输入网址(或者ip),访问到tomcat,浏览器当中出现的是tomcat的欢迎界面,如下:

那么如何能够输入地址以后能够访问到我们自己发布的默认欢迎界面呢?方法如下:

一、打开tomcat/conf/server.xml文件,找到如下代码段:

<Host name="localhost" appBase="webapps"unpackWARs="true" autoDeploy="true"><!-- SingleSignOn valve, share authentication between web applicationsDocumentation at: /docs/config/valve.html --><!--<Valve className="org.apache.catalina.authenticator.SingleSignOn" />--><!-- Access log processes all example.Documentation at: /docs/config/valve.htmlNote: 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" /></Host>

二、在<Host></Host>标签之间添加一行代码:

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

改完以后如下:

<Host name="localhost" appBase="webapps"unpackWARs="true" autoDeploy="true"></span><p><span style="font-size:14px;"><span style="white-space:pre"></span><Context path="" docBase="now" debug="0" reloadable="true" /></span></p><span style="font-size:14px;"><!-- SingleSignOn valve, share authentication between web applicationsDocumentation at: /docs/config/valve.html --><!--<Valve className="org.apache.catalina.authenticator.SingleSignOn" />--><!-- Access log processes all example.Documentation at: /docs/config/valve.htmlNote: 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" /></Host>

其中path是说明虚拟目录的名字,如果你要只输入ip地址就显示主页,则该键值留为空;debug和reloadable一般就设置成0和true就行了。实际上要改动的就是

docBase这个量,它指定的是登录tomcat默认的主页所在的文件夹,这个量默认情况下指定的是ROOT文件夹,现在改成now文件夹,所以我们需要在webapps目录下,新建一个now文件夹,然后把我们自己的网页文件放到now文件夹。然后我们需要有一个index.html 或者index.jsp的文件,在Web.xml文件当中有指定,会按照顺序去寻找index开头的文件,顺序如下:

<welcome-file-list><welcome-file>index.html</welcome-file><welcome-file>index.htm</welcome-file><welcome-file>index.jsp</welcome-file></welcome-file-list>

这是tomcat conf/web.xml文件的设置,也就是说我们放在now文件夹下的文件,需要有一个是上面三个文件的名字之一,这样tomcat就会加载对应文件,作为默认欢迎主页(当然也可以在conf/web.xml里面改默认主页的名字)。

以上设置完毕。

PS:如果想要更改tomcat默认端口,不想再网址后面加上8080,也可以通过修改server.xml这个文件来实现,找到以下代码:

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

把8080改成80端口就行了,这样就不用指定端口了。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。