
Resource references are used to obtain connections to factories for various resource manager objects. On the J2EE Engine, these include:
On the web.xml screen of your Web Module project, proceed as follows:
The name you specify in this field may not be the real JNDI name of the resource you are referencing. If this is the case, you must additionally perform the steps described below in "Mapping the Reference Name to the JNDI Name of the Resource Using web-j2ee-engine.xml".
Mapping the Reference Name to the JNDI Name of the Resource Using web-j2ee-engine.xml
If you have specified a custom name of the resource reference in the Resource Reference Name field in the web.xml, then you must map it to the real JNDI name with which the resource is bound to the naming. This is necessary to be able to look that resource up in your code.
You define the mapping using the web-j2ee-engine.xml screen of your Web Module project. Proceed as follows:
The value you must enter in the JNDI Name field depends on the type of the resource you reference:
Resource of Type javax.mail.Session
To get a resource of type javax.mail.Session the web.xml descriptor can be as follows:
<resource-ref> <res-ref-name>mail/Session</res-ref-name> <res-type>javax.mail.Session</res-type> <res-auth>Container</res-auth> </resource-ref>
Resource of Type java.net.URL
We need to redirect an HTTP request to a URL available as JNDI resource. The following source code retrieves the corresponding java.net.URL resource and redirects the client request to it.
InitialContext context = new InitialContext();
URL yahoo=(URL)context.lookup("java:comp/env/url/Yahoo.com");
response.sendRedirect(yahoo.toString());We describe the reference to that resource in the web.xml as follows:
<resource-ref> <res-ref-name>url/Yahoo.com</res-ref-name> <res-type>java.net.URL</res-type> <res-auth>Container</res-auth> </resource-ref>
We describe the reference to that resource in the web-j2ee-engine.xml as follows:
<resource-ref> <res-ref-name>url/Yahoo.com</res-ref-name> <res-link>http://www.yahoo.com</res-link> </resource-ref>
More information about the web-j2ee-engine.xml deployment descriptor: