Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Note

With servlet2.5 spec, many of the declarations done through web.xml can also be done through corresponding annotations in the servlets and JSPs

The web module connects to back end datasource using its JNDI name jdbc/DataSource as specified in the web.xml.

Code Block
xml
xml
borderStylesolid
titlegeronimo-web.xml
<web-app xmlns="http://geronimo.apache.org/xml/ns/j2ee/web-2.0.1"
          xmlns:naming="http://geronimo.apache.org/xml/ns/naming-1.2"
          xmlns:sec="http://geronimo.apache.org/xml/ns/security-2.0"
          xmlns:sys="http://geronimo.apache.org/xml/ns/deployment-1.2">

     <sys:environment>
         <sys:moduleId>
             <sys:groupId>samples</sys:groupId>
             <sys:artifactId>EmployeeDemo</sys:artifactId>
             <sys:version>2.1<5</sys:version>
             <sys:type>war</sys:type>
         </sys:moduleId>
         <sys:dependencies>
             <sys:dependency>
                 <sys:groupId> samples<groupId>samples</sys:groupId>
                 <sys:artifactId>EmployeeDatasource</sys:artifactId>
                 <sys:version>2.1<5</sys:version>
                 <sys:type>rar</sys:type>
             </sys:dependency>
         </sys:dependencies>
     </sys:environment>

     <context-root>/EmployeeDemo</context-root>

     <naming:resource-ref>
         <naming:ref-name>jdbc/DataSource</naming:ref-name>
         <naming:resource-link>jdbc/EmployeeDatasource</naming:resource-link>
     </naming:resource-ref>


 </web-app>

Please observe the different namespace prefixes Observe the various XML tags and corresponding namespaces used to configure dependencies and resource mapping. Also observe how the Datasource name jdbc/DataSource in the web.xml is mapped to jdbc/EmployeeDatasource in the geronimo-web.xml. The jdbc/EmployeeDatasource is the name of the Datasource (database connection pool) deployed on the server for connecting to back end DB2 database.in the deployment plan for various purposes.

<sys:environment> .. </sys:environment>: These elements provide the moduleid configuration and the dependencies. The moduleid elements provide the configuration name for the web module. So, when the web module is deployed, it is given the configuration name samples/samples/2.5/jar. The dependencies elements provide the configurations and third party libraries on which the web module is dependent on. These configurations and libraries will be available to the web module via a classloader hierarchy. In this case, the web module is dependent The deployment plan starts with <sys:moduleId> to provide a unique module id configuration for the web application. In dependencies section, using <sys:dependency>, a dependency on samples/EmployeeDatasource/2.1/rar is configured. This is the module id of Datasource that connects to DB2. The web context root is configured by <context-root>. Since there is no which is the configuration of the deployed Datasource that connects to a back end DB2 database. The Datasource deploys a database connection pool (javax.sql.Datasource) with name jdbc/EmployeeDatasource.

{<naming:resource-ref> .. </naming:resource-ref>}} : These elements help us to configure the resource references. In this case, the datasource reference jdbc/DataSource is mapped to jdbc/EmployeeDatasource.

In the EMPdemo.jsp, the following java code snippet is used to obtain a connection from the datasource.

Code Block
JAVA
JAVA
borderStylesolid
titleEMPdemo.jsp

....
....
Context initContext = new InitialContext();
Context envContext  = (Context)initContext.lookup("java:comp/env");
DataSource ds = (DataSource)envContext.lookup("jdbc/DataSource");
Connection con = ds.getConnection();
....
....

The above descriptor and the plan files are the simple illustrations that explain how web modules are developed and assembled for apache geronimo. Similarly, many other configurations can be performed in the geronimo-web.xml. The schema for the plan is namespace prefix for this tag, it is the default namespace http://geronimo.apache.org/xml/ns/j2ee/web-2.0.1.

All the XML schema files are located at <geronimo_home>/schema directory. Please go through the .xsd files to have a feel of XML tags that can be used in geronimo-web.xml for configuring web applications.Similarly, many container specific configurations and application security configurations are performed through other XML tags.