BeginnersBook

  • Home
  • Java
    • Java OOPs
    • Java Collections
    • Java Examples
  • C
    • C Examples
  • C++
    • C++ Examples
  • DBMS
  • Computer Network
  • Python
    • Python Examples
  • More…
    • jQuery
    • Kotlin
    • WordPress
    • SEO
    • JSON
    • JSP
    • JSTL
    • Servlet
    • MongoDB
    • XML
    • Perl

welcome-file-list tag in web.xml file of Project

By Chaitanya Singh | Filed Under: Java Servlet tutorial

❮ PreviousNext ❯

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.

❮ PreviousNext ❯

Comments

  1. Vinay says

    June 26, 2014 at 3:20 PM

    Thanks for the article. Can you also provide the directory structure under which the file should be placed so server can pick it.

    Reply
    • Chaitanya Singh says

      July 24, 2017 at 5:49 AM

      It should be under WEB-INF folder. The path should look like this: WEB-INF/web.xml

      Reply
  2. Farzana says

    July 22, 2014 at 5:11 AM

    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?

    Reply
  3. Lakshmideepak says

    October 15, 2014 at 2:52 AM

    I want to run all 4 HTML files at time from welcome list tag. Why we need list of. Welcome files in list tag.

    Reply
  4. himanshu vyas says

    November 27, 2014 at 4:33 AM

    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

    Reply
  5. sindhupriya says

    November 28, 2014 at 10:01 AM

    If there is no welcome file is defined in web.xml, how the flow will start to run the application

    Reply
  6. Adish Jain says

    April 8, 2015 at 8:31 AM

    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”

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Servlet Tutorial

  • Servlet Introduction
  • Servlet API
  • Servlet Interface
  • Generic Servlet
  • HttpServlet
  • Servlet in Eclipse
  • Servlet Life cycle
  • Working of Servlet
  • Welcome-file-list
  • load-on-startup tag
  • ServletRequest
  • RequestDispatcher
  • ServletConfig
  • ServletContext
  • ServletResponse
  • HttpSession
  • Cookies
  • Servlet Interview Q

Copyright © 2012 – 2022 BeginnersBook . Privacy Policy . Sitemap