welcome-file-list in web.xml

welcome-file-list:

The welcome-file-list attribute of web.xml file is used to define the list of welcome files.

Sample code of welcome-file-list attribute in web.xml:

<web-app>  
 
  //other attributes
 
  <welcome-file-list>  
    <welcome-file>home.html</welcome-file>  
    <welcome-file>welcome.html</welcome-file>  
  </welcome-file-list>  
 
  //other attributes
 
</web-app>

How it works:

First web server looks for welcome-file-list if it exist then it looks for file defined in first welcome-file. If this file exists then control is transferred to this file otherwise web server will look at the next welcome file and so on.

If the welcome-file-list is not exists or files defined in welcome-file-list are not exists then server will looks at the default welcome files in following order index.html, index.htm, index.jsp, default.html, default.htm and default.jsp.

Default welcome file list:

<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>

Example of welcome-file-list:

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns="http://java.sun.com/xml/ns/javaee" 
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
id="WebApp_ID" version="2.5">
 
  <welcome-file-list>
    <welcome-file>welcome.html</welcome-file>
  </welcome-file-list>
 
</web-app>

welcome.html

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 
Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>welcome</title>
</head>
	<body>
		<h1>This is a welcome file list program.</h1>  
	</body>
</html>

Output:

servlet example 4
 
Download this example.
 
Next Topic: load-on-startup in web.xml with example.
Previous Topic: Deployment Descriptor: web.xml file with example.

 

Content Protection by DMCA.com
Please Share