Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 4.0

...

For example, the following web.xml and geronimo-web.xml are the deployment descriptor and Geronimo deployment plan respectively, of a web application that connects to a datasource deployed on DB2 and retrieves data from a table.

Code Block
xmlxml
borderStylesolid
titleweb.xml
xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
         http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
    
    <resource-ref>
        <res-ref-name>jdbc/DataSource</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Container</res-auth>
        <res-sharing-scope>Shareable</res-sharing-scope>
    </resource-ref>
    
    <welcome-file-list>
        <welcome-file>jsp/EMPdemo.jsp</welcome-file>
    </welcome-file-list>
</web-app>
Note

The default namespace of the above XML document is http://java.sun.com/xml/ns/javaeeImage Removed. The XML elements that do not have a namespace prefix belong to the default namespace.

With Servlet 2.5 specification, many of the declarations done through web.xml can also be done through corresponding annotations in the servlets and JSPs. When both annotations and web.xml are provided, the declarations in web.xml takes precedence over annotations.

...

In geronimo-web.xml, a <dependency> element is added to make the the resource archive (RAR) visible to your application, and then a mapping is provided in <resource-ref>.

Code Block
xmlxml
borderStylesolid
titlegeronimo-web.xml
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.5</sys:version>
            <sys:type>war</sys:type>
        </sys:moduleId>
        
        <sys:dependencies>
            <sys:dependency>
                <sys:groupId>samples</sys:groupId>
                <sys:artifactId>EmployeeDatasource</sys:artifactId>
                <sys:version>2.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>
Note

The default namespace of the above XML document is http://geronimo.apache.org/xml/ns/j2ee/web-2.0.1Image Removed. The XML elements that do not have a namespace prefix belong to the default namespace.

...

In the EMPdemo.jsp, the following java code snippet is used to obtain a connection from the datasource. It reference the resource from the java:comp/env context entries.

Code Block
JAVAJAVA
borderStylesolid
titleEMPdemo.jsp
JAVA
....
....
Context initContext = new InitialContext();
Context envContext  = (Context)initContext.lookup("java:comp/env");
DataSource ds = (DataSource)envContext.lookup("jdbc/DataSource");
Connection con = ds.getConnection();
....
....

...

Container specific configuration in a web application

Include Page
GMOxDOC22:Providing container specific settings for your Web applicationGMOxDOC22:
Providing container specific settings for your Web application