web.xml中的welcome-file-list(欢迎页)
2017-08-18 09:51
369 查看
welcome-file-list是一个配置在web.xml中的一个欢迎页,用于当用户在url中输入工程名称或者输入web容器url(如http://localhost:8080/)时直接跳转的页面.
例如:
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>index.action</welcome-file>
</welcome-file-list>
直接输入localhost:8080/不是跳转到index.html,而是报404找不到的错误,根据错误信息看明显是没有跳转到index.html,意思就是说welcome-file-list根本就木有起作用。
解决问题一定要从原理入手,所以要先分析welcome-file-list是怎么工作的。
welcome-file-list的工作原理是,按照welcome-file的.list一个一个去检查是否web目录下面存在这个文件,如果存在,继续下面的工作(或者跳转到index.html页面,或者配置有struts的,会直接struts的过滤工作).如上例,先去webcontent(这里是Eclipse的工程目录根目录)下是否真的存在index.html这个文件,如果不存在去找是否存在index.jsp这个文件,以此类推。
还要说的是welcome-file不一定是html或者jsp等文件,也可以是直接访问一个action。就像我上面配置的一样,但要注意的是,一定要在webcontent下面建立一个index.action的空文件,然后使用struts配置去跳转,不然web找不到index.action这个文件,会报404错误,原因就是我之前说的那样。
如果配置了servlet的url-pattern是/*,那么访问localhost:8080/会匹配到该servlet上,而不是匹配welcome-file-list;如果url-pattern是/(该servlet即为默认servlet),如果其他匹配模式都没有匹配到,则会匹配welcome-file-list。
例如:
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>index.action</welcome-file>
</welcome-file-list>
直接输入localhost:8080/不是跳转到index.html,而是报404找不到的错误,根据错误信息看明显是没有跳转到index.html,意思就是说welcome-file-list根本就木有起作用。
解决问题一定要从原理入手,所以要先分析welcome-file-list是怎么工作的。
welcome-file-list的工作原理是,按照welcome-file的.list一个一个去检查是否web目录下面存在这个文件,如果存在,继续下面的工作(或者跳转到index.html页面,或者配置有struts的,会直接struts的过滤工作).如上例,先去webcontent(这里是Eclipse的工程目录根目录)下是否真的存在index.html这个文件,如果不存在去找是否存在index.jsp这个文件,以此类推。
还要说的是welcome-file不一定是html或者jsp等文件,也可以是直接访问一个action。就像我上面配置的一样,但要注意的是,一定要在webcontent下面建立一个index.action的空文件,然后使用struts配置去跳转,不然web找不到index.action这个文件,会报404错误,原因就是我之前说的那样。
如果配置了servlet的url-pattern是/*,那么访问localhost:8080/会匹配到该servlet上,而不是匹配welcome-file-list;如果url-pattern是/(该servlet即为默认servlet),如果其他匹配模式都没有匹配到,则会匹配welcome-file-list。
相关文章推荐
- 关于web.xml中的welcome-file-list(欢迎页)
- 关于web.xml中的welcome-file-list(欢迎页)
- 关于web.xml中<welcome-file-list>
- web.xml中的welcome-file-list不起作用
- java web.xml welcome-file-list的默认值
- web.xml(7)_mime-mapping、welcome-file-list、error-page
- web.xml(7)_mime-mapping、welcome-file-list、error-page
- web.xml中的welcome-file-list不起作用
- java web.xml welcome-file-list的默认值
- web.xml中的welcome-file-list
- 关于web.xml中的<welcome-file-list>中的默认首页文件
- web.xml之welcome-file-list、error-page
- Jetty下web.xml的welcome-file-list无效
- web.xml里面的welcome-file-list是什么意思
- java web.xml welcome-file-list的默认值
- web project 中利用 web.xml 中的 默认welcome-file-list 做跳转
- 【XML】web.xml中welcome-file-list的作用
- 关于web.xml中的<welcome-file-list>中的默认首页文件
- web.xml中welcome-file配置的问题
- 关于welcome-file-list(欢迎页)不起作用的解决办法