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:
http://localhost:8080/MyServletProject
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:
1) index.html
2) index.htm
3) index.jsp
I hope I covered everything related to this tag. Should you have any questions, feel free to drop a comment below.
Vinay says
Thanks for the article. Can you also provide the directory structure under which the file should be placed so server can pick it.
Chaitanya Singh says
It should be under WEB-INF folder. The path should look like this: WEB-INF/web.xml
Farzana says
Hi, without welcome file how can we tell our servlet to execute particular page. moreover can we use annotation to describe welcome file. if yes , how?
Lakshmideepak says
I want to run all 4 HTML files at time from welcome list tag. Why we need list of. Welcome files in list tag.
himanshu vyas says
during a program i faced a problem…wHen I Am using doGet method in my program
IT IS SHOWING ERROR–>
2.html
IT IS WORKING–>
/2.html
sindhupriya says
If there is no welcome file is defined in web.xml, how the flow will start to run the application
Adish Jain says
I have defined the welcome-list in web.xml but if I am running the application, I am getting the error page 404 saying “Requested resource not available”