A resource reference is used to obtain database connections and JavaMail sessions. A resource reference allows you to obtain resource factories using JNDI, rather than hard-coding connection parameters in your Web application.
Resource references have the following JNDI prefixes:
java:comp/env/jdbc for JDBC javax.sql.DataSource references. For example, if you enter jdbc/EStoreDataSource in EAServer Manager, use java:comp/env/jdbc/EStoreDataSource to lookup the data source in your source code.
java:comp/env/mail for JavaMail session references. For example, if you enter mail/MailSession in EAServer Manager, use java:comp/env/mail/MailSession to lookup the data source in your source code
java:comp/env/url for java.net.URL references. For example, if you enter url/MyFile in EAServer Manager, use java:comp/env/url/MyFile to lookup the data source in your source code
To add a resource reference:
Select web.xml in the WorkSpace Navigator of the Web Application Development perspective.
The web.xml editor opens.
Select the Resource tab of the editor.
The Resource page appears displaying defined resources and general information, filter mappings, initialization parameters, and icons for the selected filter.
Click Add.
A new resource is added to the Resource References list with the default name New ResourceRefx.
Change the default resource name in the Name field of the General Information section.
This is the partial JNDI name used in servlet and JSP code. Use the prefix mail/ for JavaMail references, jdbc/ for data source references, url/ for java.net.URL references, and jms/ for javax.jms references. For example, if your code refers to java:comp/env/jdbc/MyDatabase, typejdbc/MyDatabase in the Name field.
Click the arrow in the Type field to open the drop-down list and select one of the following
Click the arrow in the Authentication field to open the drop-down list and select the source of the authentication credentials, either Container or Application.
Select Container to use the credentials of the caller who logged into EAServer and created the component instance.
Select Application to use the credentials configured for the connection cache.
Click the arrow in the Sharing field to open the drop-down list and select either Shareable or Unshareable.
By default, connections to a resource manager are shareable across EJBs in an application that use the same resource in the same transaction context. This is available only to Web applications and EJB components.
(Optional) Type a description for the resource in the Description field.
(EAServer Only) If you are using EAServer, in the WorkSpace Navigator, expand webroot, expand META-INF, and select sybase-easerver-config.xml.
You must modify this file to point to the configured resource in EAServer.
Specify the resource link for the resource type.
Resource links
Type | Link |
---|---|
javax.sql.DataSource | Select the name of the EAServer connection cache or connector to use for this resource. |
java.mail.Session | Specify the SMTP mail server for outgoing mail. |
java.net.url | Type the URL string, as it would be used to construct a java.net.URL instance by calling the URL(java.lang.String) constructor. URLs must contain a protocol and host address, for example: http://www.sybase.com or ftp://pub.sybase.com. |
javax.jms.QueueConnectionFactory | Select the name of the queue connection factory. |
javax.jms.TopicConnectionFactory | Select the name of the topic connection factory. |
Send your feedback on this help topic to Sybase Tech Pubs: pubs@sybase.com