Saturday, September 6, 2025
HomeLanguagesJavaServlet – welcome-file-list in web.xml

Servlet – welcome-file-list in web.xml

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"?>
         xmlns="http://xmlns.jcp.org/xml/ns/javaee" 
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
                             http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd
         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:

RELATED ARTICLES

Most Popular

Dominic
32270 POSTS0 COMMENTS
Milvus
82 POSTS0 COMMENTS
Nango Kala
6639 POSTS0 COMMENTS
Nicole Veronica
11803 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11869 POSTS0 COMMENTS
Shaida Kate Naidoo
6752 POSTS0 COMMENTS
Ted Musemwa
7029 POSTS0 COMMENTS
Thapelo Manthata
6705 POSTS0 COMMENTS
Umr Jansen
6721 POSTS0 COMMENTS