Servlet之web.xml下welcome-file-list简介说明
下文讲述web.xml下welcome-file-list选项的简介说明,如下所示:
welcome-file-list子元素用于定义欢迎文件列表
子元素为welcome-file
web.xml
欢迎页面的访问优先级分别为index.html>index.jsp>test.jsp
当index.html存在时,则返回index.html
否则查找是否存在index.jsp 如果存在,则返回index.jsp
如果以上两个都不存在时,则查找test.jsp,如果存在,则返回test.jsp
否则返回404
welcome-file-list选项的用途
在web.xml文件的web-app下的welcome-file-list子元素用于定义欢迎文件列表
子元素为welcome-file
用于设置项目默认的加载页面地址
注意事项:
当未找到welcome-file-list下的文件或未设置其信息,
则默认都会返回404错误
例:web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
id="WebApp_ID" version="3.1">
<display-name>helloworld</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>test.jsp</welcome-file>
</welcome-file-list>
</web-app>
以上设置的欢迎页面分别为:index.html,index.jsp,test.jsp欢迎页面的访问优先级分别为index.html>index.jsp>test.jsp
当index.html存在时,则返回index.html
否则查找是否存在index.jsp 如果存在,则返回index.jsp
如果以上两个都不存在时,则查找test.jsp,如果存在,则返回test.jsp
否则返回404
版权声明
本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。


