Use of Deployment Descriptor in java

Introduction 

 
In this blog, I will explain to you the deployment descriptor used in a web application in java. Deployment Descriptor is a simple XML document that is used to map URL to the servlet. It tells the container how to run servlet and JSP. In a web application, Deployment Descriptor file is saved with the name web.xml.
  
There are two XML elements that are used to map the URL to the servlet.
  1. <servlet>- it maps the internal name to servlet class name
  2. <servlet-mapping>-  it maps the internal name to public name.
Now, first let us know about these internal, public and class names of the servlet. A servlet can have three names.These are:-
  1. Class name - A servlet is given a Class name by the developer who created it. The full path of a servlet file is a combination of the servlet class name and its location on the server.
    Example-:  classes/record/SignUpServlet.class
  2. Internal name - Servlet can also be given a deployment name. It is a secret internal name that can be same or different from the class name
  3. Public name - Servlet has a public name that is coded in HTML. Client knows that name and use it in URL to call the servlet.
A deployment descriptor file with both these elements look like-:
  1. < servlet > < servlet - name > Internal1 < /servlet-name><servlet-class>src.Servlet1</servlet - class > < /servlet><servlet-mapping><servlet-name>Internal1</servlet - name > < URL - pattern > /public1</URL - pattern > < /servlet-mapping>  
In the above XML, the value of the servlet-name tag is the internal name of the servlet, the value of servlet class tag is the class name of servlet and the value of URL pattern tag is the public name of the servlet.
 
Now, how the two XML element maps the URL to servlet:-
  1. <servlet-mapping> tag maps the internal name with the public name of the servlet.
  2. < servlet > tag maps the internal name with the class name of the servlet.
This is how the container loads the servlet that the client has requested. This is one of the use of Deployment Descriptor .Some of the other uses of this file is to customize the web application like security code, error pages.
 
I hope this article was useful to you and thank you for reading it.