web.xml
Servlet Deployment Descriptor Files
It is an xml file which acts as a mediator between a web application developer and a web container. It is also called Deployment Descriptor Files.
Note: we can not change the directory or extension name of this web.xml because it is standard name to recognized by container at run-time.
In web.xml file, we configure the following
- Servlet
- JSP
- Filter
- Listeness
- Welcome files
- Security
- etc....
To configure a servlet file we need the following two xml tag.
- <Servlet>
- <Serlet-mapping>
<servlet>: tag are used for configure the servlet, Within this tag we write Servlet name and class name.
<Serlet-mapping>: tag are used for map the servlet to a URL .
The structure of web.xml files is already defined by sun MicroSystem. So as a developer we should follows the structure to develop the configuration of web resources.
While configuring a servlet in web.xml, three names are added for it.
- Alias name or register name
- Fully qualified class name
- url-pattern
Syntax
<web-app> <servlet> <servlet-name>alias name</servlet-name> <servlet-class>fully qualified class name</servlet-class> </servlet> <servlet-mapping> <servlet-name>alias name</servlet-name> <url-pattern>/url pattern</url-pattern> </servlet-mapping> </web-app>