web.xml file

Creating a servlet class is not enough. We have to deploy that class also. So, to deploy the class we use web.xml file. In this file we have to map our class configurations.

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" 
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" 
id="WebApp_ID" version="3.0">
  <display-name>Filename</display-name>
<servlet>
<servlet-name>ServletName</servlet-name> 
<servlet-class>ClassName</servlet-class>
<servlet>
<servlet-mapping>
<servlet-name>ServletName</servlet-name>
<url-pattern>/PathName</url-pattern>
</servlet-mapping>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
</web-app>

We just required to edit and add some tag in our web.xml file through a text editor. Each tag contains some unique specification.

<servlet-name>: We can provide any specific name that represents a servlet class. The name can be same as of class name.

<servlet-class>: A name of servlet class is given with this tag.

<welcome-file-list>: If we want to attach other files such as html, htm, jsp with our servlet class then we have to deploy that file in this tag. Here each file is mapped separately in <welcome-file> tag.