Latest Tutorials| Questions and Answers|Ask Questions?|Site Map

Home Servlets Servlet3 Introduction to web fragment

Related Tutorials


Share on Google+Share on Google+

Introduction to web fragment

This section contains elaborated introduction of Servlet 3.0 web fragment.

Introduction to web fragment

This section contains elaborated introduction of Servlet 3.0 web fragment.

What is web fragment ?

The web fragment introduces in Servlet 3.0. It offers less configuration and improved pluggability to developers. A web fragment is a portion or all of the deployment descriptor(web.xml). It can be defined and enclosed in the jar file's META-INF of a framework or library. The container employs the configuration as describe in the web fragment.

A web fragment provide logical division of the web application so that the frameworks used within the web application can specify all the artifacts without requiring developers to edit or add any info in the web.xml. It employed nearly all the elements of the deployment descriptor(web.xml).

More than one web fragment can be employed. Each web fragment describe logical division. All these web fragment should be considered as complete web.xml(deployment descriptor). The web fragment provide capability to the frameworks to auto register to the web container.

Rules for utilizing web fragment

Following things should be keep in the mind before implementing web fragment :

  • The web fragment must reside in a file having name web-fragment.xml.

  • The top level descriptor in web-fragment.xml must be <web-fragment>.

  • The web fragment must put inside framework's JAR file's META-INF directory. This jar file must placed inside the web application's WEB-INF/lib directory.

  • The web application's deployment descriptor have a new <metadata-complete> property . If it is sets true, annotations present in application's classes , and web fragments is ignore by the deployment tool. If it sets false or not described , annotations present in application's classes , and web fragments is examine by the deployment tool.


Given below the sample web fragment :


<?xml version="1.0" encoding="UTF-8"?>
<web-fragment xmlns:xsi="" xmlns="" xmlns:web="" xsi:schemaLocation="" id="WebAppFragment_ID" version="3.0">



If you enjoyed this post then why not add us on Google+? Add us to your Circles

Liked it!  Share this Tutorial

Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: June 30, 2012

Related Tutorials

Discuss: Introduction to web fragment  

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image