Understanding Deployment Descriptor


Basically, a deployment descriptor refers to a configuration file in a web application. Whenever we create a J2EE application, it includes web components comprising of servlets and JSP files, For the purpose of managing the dynamic web application, we can create a web.xml file. In fact, the web.xml is our deployment descriptor.

This web.xml file contains information regarding URL mapping, registering servlets, initialization parameters, context parameters, authentication requirements, and so on. Since it is an XML file, the information it contains is in the form of XML tags.

Elements of Deployment Descriptor

The following list describes some of the frequently used elements of the web.xml file.


As soon as the request arrives that includes a directory name, the web server selects the first file from the list contained in the <welcome-file-list> element. For instance, it selects the index.html as the default file to open.


Basically, we use the <servlet> element to register a servlet. It contains information regarding servlet name, servlet class, initialization parameters, and so on.


In order to specify a URL pattern for a servlet, we use this element. For instance, we can specify a URL pattern of /myservlet for a servlet named FirstServlet.


Within this element, we define the session attributes. For instance, we can specify session timeout in the <servlet-config> element.


Basically, we use this element to specify a name for the web application.


In order to specify the context initialization parameters, we use this element. In fact, the context initialization parameters are specified as name-value pairs. Further, these parameters are available in all servlets contained in the web application.


In fact, we can display a resource such as a JSP page when an error occurs or an exception is thrown. In other words, this element specifies a resource in response to an error code.


In order to register a class that responds when a specific web application event occurs, we use this element.


For the purpose of describing a JSP tag library, we use this element.


You may also like...