To understand web.xml, first let us uderstand what is xml?

  • xml stands Extensible Markup Language.
  • xml is markup language much like html.
  • Xml defines set of rules for encoding document in a format that readable by both as human and machine.
  • Xml was designed to carry and store data, not to display data. Xml is designed to be self-descriptive.

Web.xml defines mapping between URL paths and servlets that handle requests with those paths. The web.xml file provides configuration and deployment deployment information for the Web components that comprise a Web application. The web.xml descriptor files represents the core of the java application. The web.xml file is located in WEB-INF directory of web application.

Example of web.xml File:


Elements in Web.xml

Description of elements Used in web.xml file:

  1. <web-aap>: This element represents whole application of web.xml file
  2. <servlet>: This is the sub element of and represents the servlet
  3. <servlet-name>: This is the sub element of servlet and used to represents the name of servlet
  4. <servlet-class>: This is the sub element of servlet and used to represents the class of servlet
  5. <servlet-mapping>: This is the sub element of and used to map the servlet
  6. <url-pattern>: This is the sub element of servlet-mapping and used to client side to invoke the servlet

Web.xml Tags

Tags used in web.xml file are:

  1. Welcome-file-list tag; This tag is used to specify the default page of web application if none is specified.


    In the above example index.jsp used as web page for web application

  2. Session config tag: This tag is used to specify the session configuration parameter


    In the above example session-config tag contains another tag session-timeout which specifies the http session timeout. The time specify in minutes.

  3. Error page tag: This tag is used to specify the error occurred in the while weblogic server is responding ti a HTTP request, returns an HTML page that displays either the HTTP error code.
    </error page>

    In the above example error-page tag specify the error code as 105 and location describes the location of the jsp page.

Advantages of web.xml file

  • The first benefit of the xml is we can write it in our won markup language. There is a no restricted to limited sets of tags. By defining our own tag we can create a markup language in terms of specific problem.
  • Searching the data is easy and efficient.
  • Completely compatible with Java™ and 100% portable.

Previous Tutorial : Servlet Example  || Next Tutorial : Servlet Context

Leave a Reply

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

Pin It on Pinterest

Share This

Share this post with your friends!