Wednesday, 30 September 2015

welcome-file-list in web.xml

welcome-file-list in web.xml

The welcome-file-list element of web-app, is used to define a list of welcome files. Its sub element is welcome-file that is used to define the welcome file.
welcome file is the file that is invoked automatically by the server, if you don't specify any file name.
By default server looks for the welcome file in following order:
  1. welcome-file-list in web.xml
  2. index.html
  3. index.htm
  4. index.jsp
If none of these files are found, server renders 404 error.
If you have specified welcome-file in web.xml, and all the files index.html, index.htm and index.jsp exists, priority goes to welcome-file.
If welcome-file-list entry doesn't exist in web.xml file, priority goes to index.html file then index.htm and at last index.jsp file.
Let's see the web.xml file that defines the welcome files.
web.xml
  1. <web-app>  
  2.  ....  
  3.   
  4.   <welcome-file-list>  
  5.    <welcome-file>home.html</welcome-file>  
  6.    <welcome-file>default.html</welcome-file>  
  7.   </welcome-file-list>  
  8. </web-app>  
Now, home.html and default.html will be the welcome files.
If you have the welcome file, you can directory invoke the project as given below:
  1. http://localhost:8888/myproject  
As you can see, we have not specified any file name after the project.

No comments:

Post a Comment