How to Write Deployment Descriptor,web.xml In Servlet

Servlets » on Jan 5, 2013 { 22 Comments } By Sivateja

This web.xml is like index of book, web.xml is containing details of static web resource programs and dynamic web resource programs.  The purpose of web.xml is to hide [or] to achieve the security for the web application by not showing [ in the URL ] the type of technology used for development of web application.

Deployment Descriptor [ web.xml ] in Servlets


    <servlet-name> Give Some Dummy Name </servlet-name>
    <servlet-class>/Flly qualified name of our servlet</servlet-class>
    <servlet-name> Give Some Dummy Name </servlet-name>
  • We must call our servlet by typing its <url-pattern> only
  • For example http://localhost:8080/OurServletApplicationFolderName/UserFriendlyName
  • Once we call our servlet just like above, then the server will first loads web.xml and verifies whether the url pattern we are calling is same as what in <url-pattern> tag in web.xml [Line number 8] or not
  • If matched, it will checks the <servlet-name> [Line number 7] and will jump to <servlet-name> [Line number 3] in <servlet> tag and, will check whether the value of <servlet-name> in line number 3 & line number 7 are same or not if same it will load our class in <servlet-class> [line number 4]
  • Finally our .class file will be executed, so we can check the output


You Might Also Like

  ::. About the Author .::

Sivateja Kandula - Java/J2EE Full Stack Developer
Founder of Java4s - Get It Yourself, A popular Java/J2EE Programming Blog, Love Java and UI frameworks.
You can sign-up for the Email Newsletter for your daily dose of Java tutorials.


22 Responses to “How to Write Deployment Descriptor,web.xml In Servlet”
  1. N kiran says:

    Hi Java4s Team,
    Really superb explanation … i really thank so much…

  2. Wesley says:

    great explanation men.. will help the newbies even more compared to other tutorials !!

  3. Shrika says:


    In the above URL, OurServletApplicationFolderName is the root folder name right?
    Can we make it case sensitive?

    I mean
    http://localhost:8080/OURSERVLETAPPLICATIONFOLDERNAME also should work.

  4. Kiran says:

    Super Duper Well Nice…

  5. This is really wonderful explanation thank you very much to giving us a great tutorial and guide us

  6. Kalaichelvi says:

    awesome explanation… Its very helpful.. Thank yu so much:-)

  7. Pankaj Kumar says:

    That is a very wonderful explanation. Before this, I searched hundreds of pages for web.xml. But they didn’t satisfy my doubt. But your this article helped me a lot.

  8. amar kumar says:

    Sir,really your description is one of the best but one doubt in my mind .Sir is it possible to check the flow of execution of web.xml file.

  9. Nandha says:

    Your Explanation is really Good .Till now I don’t know about the servlet how it runs, now its cleared

  10. prashanthi says:

    Hi sir i really like your website very explained all topics step by step superb.examples and explanaton is very nice.but not yet explained about SPRING SECURITY.we are waiting for explaination about SPRING SECURITY soon.

  11. Rohan Sutar says:

    awesome explanation…thanks

  12. sindhuja says:

    super’b explaination. every one can easily understand

  13. vadgama kapur says:

    Hi sir i really like your website thanks

  14. krishna says:

    Is it possible to write multiple web.xml files in single web application in servlet,if we can please elaborate it. Thanks

  15. sai chandra reddy says:

    really a great explanation.thank you javas4s

  16. pavanireddy says:

    This is awesome explanation,also "JAVA4S" is very useful for us for clarifying the doudt easily …….
    GREAT JOB….>thank you so much..

  17. anveshreddy says:

    I have an doubt in web.xml, what is the use of dummy name.why can't we write directly with servlet name and url pattern.?

  18. Moula Ali shaik says:

    Damn effective explanation and we are expecting more articles please.

  19. manoj kumar says:

    nice explanation….

  20. tarun says:

    How to add a validation filter to this

  21. Madhavan says:

    Hi Java4s Team,
    Really superb explanation …
    great explanation.
    keep it up.. I Follow Only

  22. Ramakrishna says:

    Superb explanation.


By posting your answer, you agree to our comments policy.
Most Recent Posts from Top Categories
Spring Boot Hibernate Spring
Contact | About Us | Privacy Policy | Advertise With Us

© 2010 - 2024 Java4s - Get It Yourself.
The content is copyrighted to Sivateja Kandula and may not be reproduced on other websites.