一、關於web.xml中的welcome-file-list
<welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> </welcome-file-list>
這個配置用於配置項目的初始頁面。
輸入http://localhost:8080/xpb,自動進入http://localhost:8080/xpnb/index.jsp
tomcat中的web.xml是通用的,如果不設置,那么就會默認是同tomcat的web.xml,如果你設置了,那么當然是項目下的web.xml中的設置優先權更高一點。
加載順序是
1、tomcat conf目錄下;
2、項目目錄下的;
tomcat config目錄下的為服務器全局作用域,一般用來配置全局設置、數據源等,而項目目錄下的為局部作用域。
也可以配置action
<welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.jsp</welcome-file> <welcome-file>index.action</welcome-file> </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。
鏈接:https://www.jianshu.com/p/0d4dc96a841f