The Wayback Machine - https://web.archive.org/web/20240723050519/https://www.geeksforgeeks.org/servlet-welcome-file-list-in-web-xml/
Open In App

Servlet – welcome-file-list in web.xml

Last Updated : 30 Jan, 2022
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report

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:



Similar Reads

How to Configure Dispatcher Servlet in web.xml File?
DispatcherServlet acts as the Front Controller for Spring-based web applications. So now what is Front Controller? So it is pretty simple. Any request is going to come into our website the front controller is going to stand in front and is going to accept all the requests and once the front controller accepts that request then this is the job of th
5 min read
Spring MVC Application Without web.xml File
Spring MVC framework enables separation of modules namely Model, View, and Controller, and seamlessly handles the application integration. This enables the developer to create complex applications also using plain java classes. Here we will be creating and running Your First Spring MVC Application, whenever we are Configuring Dispatcher Servlet we
4 min read
Automated Time-Based Reload Response in Java Web Servlet
Automated Time-Based Reload Response in Java Web Servlet comes into the picture while working with Java Servlets, we need a mechanism for page auto-reload according to our need. This automated refresh can be created in the Java servlet itself as a response. In webpages, there is a need where without clicking any button or link, the page should be a
2 min read
Servlet - Web Terminology
Servlets are the Java programs that run on the Java-enabled web server or application server. They are used to handle the request obtained from the webserver, process the request, produce the response, then send a response back to the webserver. How Servlet WorksAt the request of a servlet, the server checks if it is the first time and if it is so;
5 min read
Servlet - Web Application
Servlets are the Java programs that run on the Java-enabled web server or application server. They are used to handle the request obtained from the webserver, process the request, produce the response, then send a response back to the webserver Working With Servlets Working with Servlets is an important step in the process of Application developmen
7 min read
Servlet - Downloading File
Servlets are the Java programs that run on the Java-enabled web server or application server. They are used to handle the request obtained from the webserver, process the request, produce the response, then send a response back to the webserver. In this article, we will learn to download a file such as .docx, .pdf, .png etc,. from the server using
4 min read
Servlet - War File
A war (web archive) A web project's files are contained in this file. It may contain files such as servlet, xml, jsp, image, html, css, and js. Here, we'll go through what a war file is, how to make one, how to deploy one, and how to remove one. What is WAR File? The WAR file (Web Application Resource or Web Application ARchive) is a container for
2 min read
Servlet - Uploading File
Servlets are the Java programs that run on the Java-enabled web server or application server. They are used to handle the request obtained from the webserver, process the request, produce the response, then send a response back to the webserver. Now let us learn how to upload a file to a server in this section. In an HTML file, the method must be p
2 min read
How to Resolve WEB xml is missing and failOnMissingWebXml is set to true in Eclipse/STS?
Eclipse/STS IDE is generally used to develop Spring applications and what happens is whenever we are creating a simple Maven project and if the web.xml is missing or you have deleted that file then you may encounter this problem inside the pom.xml file corresponding to which do refer to the below image as follows: Now we are going to discuss how ca
2 min read
How to Create and Modify Properties File Form Java Program in Text and XML Format?
Properties file are a text-oriented key value a pair of contents present in a Java project with .properties extension. Line by line, the key-value pair of contents are present, and they are usually prepared by means of notepad, Wordpad, EditPlus, etc., Properties files are usually helpful to store important sensitive information and in this article
5 min read
Article Tags :
Practice Tags :
three90RightbarBannerImg