You could have seen the <welcome-file-list> tag in web.xml of your project and could have wondered the use of it. In this tutorial we will learn how to use this tag effectively.
The welcome-file-list element of web-app, is used to define a list of all welcome files which will be loaded by default, it has a sub element is welcome-file which is used to define the welcome file.
If Suppose you have created a project “MyProject”, which have its own servlets and html files, but when you call your application like below
http://localhost:8080/MyProject
instead of
http://localhost:8080/MyProject/XXX.html
Then the server will look the <welcome-file-list> tag in your web.xml, if suppose we have a entry in the web.xml for the welcome-file-list
<web-app> .... <welcome-file-list> <welcome-file>first.htm</welcome-file> <welcome-file>home.htm</welcome-file> <welcome-file>default.htm</welcome-file> </welcome-file-list> .... </web-app>
The server will start looking for “first.htm”, if it doesn’t exist then it moves to “home.htm” and so on till it finds the valid file. If the <welcome-file-list> is not found then the server will by default looks for the welcome file in following order:
- index.html
- index.htm
- index.jsp
If none of the above mentioned files are found then the server returns 404 error.
Leave a Reply