welcome-file-list in web.xml - Java Servlets


This is a simple tag used in web.xml, which specifies the file that has to be loaded when the user requests a site. Example, if myproj is my project name (i.e. name of the folder in webapps directory), and 8080 was the port in which my Tomcat was installed, then if user goes to, localhost:8080/myproj and then hits enter, what at first has to be displayed is decided by the welcome-file-list, the file that has to welcome the user. If you go to some websites just by typing address, you will be redirected to website.com/home.html like that.

index.html / index.jsp

If the file name is index.html/index.jsp, then you need not specify welcome-file-list, unless if you want to welcome user with another file. For better understand, consider your project folder containing, index.html and home.html , if you don't specify the welcome-file-list, the user will automatically be redirected to index.html because it is default file for web browsers when user just types the site address. If you want home.html to be displayed to the user when user hits your site address, then you have to specify home.html in welcome-file-list.

index.html vs index.jsp

What if the files index.html and index.jsp are present? Then index.html wins, because html is the dearest friend for browsers.

welcome-file-list syntax


my_welcome_file_path: If the welcome file resides in project's root directory, then just it's name will suffice, else you will have to specify the whole path.

Example, if welcome file is in, files folder which is in your project root, then you will have to specify, /files/mywelcomefile.html.

Note: Welcome files, can be of any name, any extension, any where.

Posted by at on

Tags: Miscellaneous,