<%-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %> <%@ taglib uri="http://java.sun.com/portlet" prefix="portlet"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>

WEB-INF/web.xml

<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
         http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
         version="2.4">

  <!--  servlets and mappings and normal web.xml stuff here -->

  <resource-ref>
    <res-ref-name>jdbc/MyDataSource</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
    <res-sharing-scope>Shareable</res-sharing-scope>
  </resource-ref>
</web-app>

WEB-INF/geronimo-web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app
    xmlns="http://geronimo.apache.org/xml/ns/j2ee/web-1.1">
    <environment>
        <moduleId>
            <artifactId>MyWebApp</artifactId>
        </moduleId>
        <dependencies>
            <dependency>
                <groupId>${pool.abstractNameMap['groupId']}</groupId>
                <artifactId>${pool.abstractNameMap['artifactId']}</artifactId>
            </dependency>
        </dependencies>
    </environment>

    <context-root>/MyWebApp</context-root>

    <!-- security settings, if any, go here -->

    <resource-ref>
        <ref-name>jdbc/MyDataSource</ref-name>
        <resource-link>${pool.name}</resource-link>
    </resource-ref>
</web-app>

<?xml version="1.0" encoding="UTF-8"?>
<web-app
    xmlns="http://geronimo.apache.org/xml/ns/j2ee/web-1.1">
    <environment>
        <moduleId>
            <artifactId>MyWebApp</artifactId>
        </moduleId>
        <dependencies>
            <dependency>
                <groupId>${pool.abstractNameMap['groupId']}</groupId>
                <artifactId>${pool.abstractNameMap['artifactId']}</artifactId>
            </dependency>
        </dependencies>
    </environment>

    <context-root>/MyWebApp</context-root>

    <!-- security settings, if any, go here -->

    <resource-ref>
        <ref-name>jdbc/MyDataSource</ref-name>
        <pattern>
          <groupId>${pool.abstractNameMap['groupId']}</groupId>
          <artifactId>${pool.abstractNameMap['artifactId']}</artifactId>
          <name>${pool.abstractNameMap['name']}</name>
        </pattern>
    </resource-ref>
</web-app>

protected void doGet(HttpServletRequest request, HttpServletResponse response) {
    try {
        InitialContext ctx = new InitialContext();
        DataSource ds = ctx.lookup("java:comp/env/jdbc/MyDataSource");
        Connection con = ds.getConnection();
    } catch(NamingException e) {
        ...
    } catch(SQLException e) {
        ...
    }
}

">