Servlet – welcome-file-list in web.xml
Last Updated :
30 Jan, 2022
The web.xml file’s welcome-file-list property is used to establish a list of welcome files. If you don’t supply a file name while loading the project in the browser, the tag <welcome-file-list> is used to define the files that will be called by the server by default. The server looks for the welcome file in the following sequence by default:
- welcome-file-list in web.xml
- index.html
- index.htm
- index.jsp
The server returns a 404 error if none of these files are found.
Code for the welcome-file-list attribute in web.xml
XML
< web-app >
....
< welcome-file-list >
< welcome-file >index.html</ welcome-file >
< welcome-file >index.htm</ welcome-file >
< welcome-file >index.jsp</ welcome-file >
< welcome-file >default.html</ welcome-file >
< welcome-file >default.htm</ welcome-file >
< welcome-file >default.jsp</ welcome-file >
</ welcome-file-list >
</ web-app >
|
Working of welcome-file-list
The welcome-file-list is the first thing that the webserver checks for. If it exists, it searches for the file specified in the initial welcome-file. If this file exists, control is sent to it; otherwise, the webserver moves on to the next welcome file, and so on. If the welcome-file-list does not exist, or if the files defined in the welcome-file-list do not exist, the server will look at the default welcome files, which are index.html, index.htm, index.jsp, default.html, default.htm, and default.jsp in that order.
Example
web.xml
XML
<? xml version = "1.0" encoding = "UTF-8" ?>
id = "WebApp_ID" version = "4.0" >
< display-name >WelcomeFileList</ display-name >
< welcome-file-list >
< welcome-file >welcome.html</ welcome-file >
</ welcome-file-list >
</ web-app >
|
welcome.html
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01
< html >
< head >
< title >welcome</ title >
</ head >
< body >
< h1 >Welcome to GeeksForGeeks</ h1 >
</ body >
</ html >
|
Output:
Share your thoughts in the comments
Please Login to comment...