You can create and configure resource references for Web
2.5 and Web 3.0 projects using the deployment descriptor.
About this task
You need to create a web project using Web 2.5 and Web 3.0
before you can create and configure resources references. Select Generate
deployment descriptor in the project creation wizard.
Procedure
- Expand your web project, and select .
- Right click web.xml and select .
- In the Web application field, select Add and select Resource Reference and click OK:
- In the Details section, provide
the details for your resource reference:
- In the Name field, provide a
name for your resource reference.
- In the Type field, provide the
type of resource reference.
- In the Authentication field,
select either Application or Container for the authentication of your resource reference.
- In the Sharing Scope field, select
either Shareable or Unshareable for the sharing scope of you resource reference.
- In the Description field, type
a description of this resource reference.
- To view the web.xml source code, select Source:
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="3.0" 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_3_0.xsd"> <servlet>
<description>
</description>
<display-name>
TestServlet</display-name>
<servlet-name>TestServlet</servlet-name>
<servlet-class>test.TestServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>TestServlet</servlet-name>
<url-pattern>
/TestServlet</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<resource-ref>
<res-ref-name>SAMPLE</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>
- To edit your resource reference, you can make changes in
either the Design or the Source view of the deployment descriptor
page.
- To bind this resource reference to a data source on the
server: with the JNDI name jdbc/SAMPLE using a JAAS authentication
alias called USER_AUTH, then you edit the ibm-web-bnd.xml file and
add the following definitions
- Right click the ibm-web-bnd.xml file and select .
- Add a resource reference:
- In the Design view, click Add.
- In the Add Item window, select Resource Reference. Click OK
- In the Name field, type the name of your
resource reference, for example: SAMPLE
- In the Binding Name field, type the of
your resource reference, for example: jdbc/SAMPLE.
- In the Design view, highlight your Resource Reference,
and click .
- In the Details section, in the Name field, provide a name for your Authentication Alias (for example,
use the JAAS authentication alias called USER_AUTH). The resulting
- To view the web.xml source code, select Source:
<?xml version="1.0" encoding="UTF-8"?>
<web-bnd
xmlns="http://websphere.ibm.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://websphere.ibm.com/xml/ns/javaee http://websphere.ibm.com/xml/ns/javaee/ibm-web-bnd_1_0.xsd"
version="1.0">
<virtual-host name="default_host" />
<resource-ref name="SAMPLE" binding-name="jdbc/SAMPLE">
<authentication-alias name="USER_AUTH" />
</resource-ref>
</web-bnd>