Java

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.

welcome-file-list

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.

servlet

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

servlet-mapping

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.

servlet-config

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

display-name

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

context-param

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.

error-page

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.

listener

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

taglib

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



Further Reading

Servlet and its Life Cycle

Input Parameters in a Servlet

Creating Arrays in Java

Java Practice Exercise

JavaScript Code Examples

Callback Functions in JavaScript

Understanding HTTP Requests and Responses

Basics of Java Programming

Examples of Decision Making in Java

Flow Control Using Loops in Java

How to Create User-Defined Methods in Java

Examples of For-each Loop in Java

Method Overloading Using Java

Interfaces in Java

Leave a Reply

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