tomcat设置默认欢迎页,或者是默认第一访问页

2016/7/9 22:59:14 | 阅7316 来源:好空间网络 [打印] [关闭]
 

tomcat设置默认欢迎页,或者是默认第一访问页!

打开web.xml 无论是tomcat自带的web.xml 还是您自己工程WEB-INF/web.xml 哪个都可以,在

<web-app> 和 </web-app>

中间增加 如下一段话

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

 这段话的意思是,当用户输入域名后,如果没有输入指定的文件名称 比如

用户输入http://www.jspkongjian.net的时候 系统默认自动访问 index.htm 如果index.htm不存在那么他将访问第二个index.jsp 以此类推~~~ 如果以上都不存在则返回404错误

 

另外在说下index.do 为结尾的 这个一般是servlet,这个文件可能真实并不存在~~ 这个时候您虽然设置了让他访问index.do 但是可能不生效!!

 

原因是因为tomcat的限制,这里必须是已经存在的文件, 如果需要他生效也很简单, 只需要在网站根目录下 建立个index.do的文件, 随便输入一点内容,保存即可!!

 

原理: tomcat会首先检查这个文件是否存在,然后检查大,最后没问题的话他就显示index.do了,当然他显示的是你的servlet,这个也算是一种欺骗tomcat的办法吧!!

 

最后附上web.xml

 

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<welcome-file-list>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>index.do</welcome-file>
</welcome-file-list>
</web-app>

 

经营许可证ICP:皖B2-20100052 公司邮箱:zcdnsz@jspkongjian.net
Copyright © 2004-2015, 安徽好空间网络科技有限公司 版权所有 , 本站素材部分来源于网络,如有侵权请告知删除。