In this blog, I will explain you about the
deployment descriptor used in a web application in java. Deployment Descriptor
is a simple xml document which is used to map URL to servlet. It tells the
container how to run servlet and JSP. In a web application, Deployment
Descriptor file is saved with name web.xml.
There are two xml elements that are used to map URL to servlet.
- <servlet>- it maps the internal name to
servlet class name
- <servlet-mapping>- it maps the internal
name to public name.
Now ,first let us know about these internal,
public and class name of servlet. A servlet can have three name .These are:-
- Class name - A servlet is given a
class name by the developer who created it. The full path of a servlet file
is combination of servlet class name and its location on server.
Example-: classes/record/SignUpServlet.class - Internal name - Servlet can also
be given a deployment name. It is a secret internal name that can be same or
different from class name
- 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 looks like-:
<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 servlet-name tag is the internal name of 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 servlet.
Now , how the two xml element maps the URL to servlet :-
- <servlet-mapping> tag maps the internal
name with the public name of servlet.
- < servlet > tag maps the internal name
with the class name of 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.