Have you ever seen
<welcome-file-list> tag in your
web.xml file and wondering what it is? In this text, I will explain what is this tag and why we use it.
The tag <welcome-file-list> is used for specifying the files that needs to be invoked by server by default, if you do not specify a file name while loading the project on browser.
For e.g. You have created a project named “MyServletProject” and you have few html pages and servlet classes defined in the project. However in browser you have given the url like this:
Usually we give the complete path like this:
http://localhost:8080/MyServletProject/index.html. However if you have given the path like above then the webserver will look for the <welcome-file-list> tag in your project’s web.xml file. Lets say you have the following content in your web.xml file:
<web-app> .... <welcome-file-list> <welcome-file>myhome.htm</welcome-file> <welcome-file>myindex.htm</welcome-file> <welcome-file>mydefaultpage.htm</welcome-file> </welcome-file-list> .... </web-app>
Based on the welcome file list, server would look for the
myhome.htm page if this doesn’t exist then the second welcome file
myindex.html and so on till it finds a valid welcome file.
Note: If the <welcome-file-list> tag is not defined in web.xml or the welcome files defined in the <welcome-file> tags does not exist then the server would look for the following files in the given sequence:
I hope I covered everything related to this tag. Should you have any questions, feel free to drop a comment below.