Home > Documentation > Reference > Samples > Java EE sample applications > webfragment-javaee6 - A simple web fragments application |
This sample demonstrates the modularity and plug-ability features in Servlet 3.0 specification, which is also call as web fragments. A web fragment is like a part of a web application, which consumes almost all the same elements as a web application within its deployment descriptor, however, the deployment descriptor of a web fragment must be named as web-fragment.xml
and put in META-INF/
directory of the fragment. And the top-level element must be <web-fragment>. You can update a web fragment without any impact to the web application.
Within the web application, all configuration files such as web.xml
and web-fragment.xml
are loaded and scanned. You can specify the ordering requirements of the web application use either <absolute-ordering> or <order> element. This sample only shows the usage of <absolute-ordering> element.
The sample application consists of following list of packages and classes.
org.apache.geronimo.samples.javaee6.webfragment.fragment1 is the first fragment of the web application
org.apache.geronimo.samples.javaee6.webfragment.fragment2 is the second fragment of the web application
org.apache.geronimo.samples.javaee6.webfragment.fragment3 is the first fragment of the web application
org.apache.geronimo.samples.javaee6.webfragment is the main body of the web application
The list of web application files in the webfragment application is depicted in the following.
+-WEB-INF
|_ web.xml
|_ geronimo-web.xml
|_ index.html
|_ header.html
|_ Sample-docu.html
geronimo-web.xml specifies the module's information and the url for the web application
Information about the project sucha as module's unique identification, dependencies is described inside the <sys:environment/> tags. It is a good practise to give a module an unique identification, so that it can later be referenced by some other deployable application. This module is in the group org.apache.geronimo.samples. The path specified in the <context-root> tag will be the entry point of this web application. Therefore you can access this web application at http://<hostname>:<port>/webfragment-javaee6.
web.xml defines the welcome page of the webfragment application and the order of resources to be composed from fragments. Using <absolute-ordering> means that web.xml must be processed first, fragment3 and fragment2 must be processed sequentially. <others/> element makes sure the other web fragments being processed before fragment1. And fragment1 is the last one to be processed.
WelcomePage.java is a servlet component which sends the request to another servlet QueryAll in fragment1.
web-fragment.xml uses the same elements as in web.xml except that the top-level element must be <web-fragment>. And metadata-complete="true" means any annotatons in the class files within this fragment will not be processed. <name>fragment1</name> must be consistent with the one in web.xml of webfragment application.
You can look into other web framents, and you will notice the similar configuration information and some other servlets which are pretty easy to understand.
Please reference Samples General Information for information on obtaining and building the source for this and other samples.
Once all the sources get checked out the next step is to build webfragment-javaee6. It requires Maven 2 for building the binaries.
From the <webfragment-javaee6_home> directory run the following command.
mvn clean install
This process will take a couple of minutes. The binaries will be generated in the corresponding target directory .
Deploying sample application is pretty straight forward as we are going to use the Geronimo Console.
The app is visible at http://localhost:8080/webfragment-javaee6/
Input the ID and quantity you want to buy, then click Add to cart
Click Go to Pay to see how much you should pay and all messages that the filter or listener classes recorded.
Bookmark this on Delicious Digg this | Privacy Policy - Copyright © 2003-2013, The Apache Software Foundation, Licensed under ASL 2.0. |