例如:
<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目錄下面存在這個文件,如果存在,繼續下面的工作,先去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,項目會自動跳轉到歡迎頁!
/和 /* 對於所用請求都攔截,但是 / 對於 .jsp 的不攔截,直接訪問到真實的jsp頁面。
<servlet> <servlet-name>hello</servlet-name> //起一個名字而已,與下面的servlet-mapping的名字一致,表示這兩個是一組 <servlet-class>com.briup.test.HelloWorld</servlet-class> //攔截請求后調用這個類去處理 </servlet> <servlet-mapping> <servlet-name>hello</servlet-name> <url-pattern>/world</url-pattern> //映射,攔截請求 </servlet-mapping>