您的位置:首页 > 其它

web.xml中的welcome-file认识

2015-08-31 00:00 260 查看
以前只知道welcome-file是用于配置首页地址,当访问域名时自动进入对应的页面,所以一直以为这个配置的是一个绝对地址。最近在一次测试中发现输入一个没有配置nginx的地址竟然可以进入一个页面,查了很久只有welcome-file这个最可疑,于是才去深扒它的说明(好吧,我承认我基础差)

顺便吐槽下,查说明只有去英文网站才查到,中文的都是说怎么用.......

This tag specifies the relative path of a single welcome file.

A welcome file is provided when the web application is accessed using only the domain name, or with any other URL that ends with a slash.

Welcome files must exist as physical files in your application, or in Servlets 2.4 and above can also be servlets that are defined in web.xml.

The page or servlet should be specified without any leading slash. Only relative paths can be specified.

OK,了解了,也就是说welcome-file配置的是相对地址,当地址只有域名或是以斜杠结尾的时候,就会匹配到welcome-file中的相对地址里,举例说明:

web.xml配置:

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


则www.baidu.com就会匹配为www.baidu.com/index.jsp

这也是最常用的大家都懂得

但如果地址为www.baidu.com/admin,则会匹配为www.baidu.com/admin/index.jsp

这个容易被别人忽略,当然提前是没有被nginx、filter或服务器拦截到而且确实有admin/index.jsp这个文件

好了,记录一下以免忘记,大神可以直接回复:然并卵......
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: