Oracle Logo

Example of Using Web Fragment

 

Web Fragment

Web-fragment.xml was added to Servlet 3.0 to enhance the pluggability of imported library JARs. The content of web.xml and web-fragment.xml are almost the same. However, now we can define the configuration information of JARs with web-fragment.xml and then conveniently plug it into a deployment descriptor file.

Description of Example

This example defines a filter in a JAR with a web-fragment.xml file. The filter is configured to obtain and print parameters from a servlet request. When deploying this application, a parameter is used to choose whether to import the JAR that includes the filter. Users can then see the function of the filter, with or without the JAR file.

Use This Example

Click "Run" to run the Web fragment example.