Adding a Resource Reference to a Web Application

A resource reference is used to obtain database connections and JavaMail sessions. It 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:


  1. In the WorkSpace Navigator of the Web Application Development perspective, select web.xml.
  2. Select the Resource tab.
  3. Click Add. A new resource is added with the default name "New ResourceRef x."
  4. 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 , type jdbc/MyDatabase in the Name field.
  5. Click the arrow in the Type field and select one of the following
    Table 1. Resource types
    Type Use for
    javax.sql.DataSource JDBC connections
    java.mail.Session JavaMail sessions
    java.net.url Aliased URLs
    javax.jms.QueueConnectionFactory JMS queue connection factories
    javax.jms.TopicConnectionFactory JMS topic connection factories
  6. Click the arrow in the Authentication field to select the source of the authentication credentials, either Container or Application.
    • Select Container to use the credentials of the caller who logged in to EAServer and created the component instance.
    • Select Application to use the credentials configured for the connection cache.
  7. Click the arrow in the Sharing field to select either Shareable or Unshareable.
    Note: 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.
  8. (Optional) Enter a description for the resource.
  9. (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.

    Table 2. 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.
Related concepts
Configuring the web.xml File
Related tasks
Adding a Servlet to a Web Application
Adding a Filter to a Web Application
Adding an EJB Reference to a Web Application
Adding a Context Parameter to a Web Application
Adding a Listener to a Web Application
Adding a Tag Library to a Web Application
Adding a Welcome File to a Web Application
Adding an Error Page to a Web Application
Adding MIME Mapping to a Web Application
Adding an EJB Local Reference to a Web Application
Adding a Resource Environment Reference to a Web Application
Adding an Environment Entry to a Web Application
Adding Security to a Web Application
Defining the Login Configuration of a Web Application

Send your feedback on this help topic to Sybase Technical Publications: pubs@sybase.com

Your comments will be sent to the technical publications staff at Sybase, Inc. For product-related issues or technical support, contact Sybase Technical Support at 1-800-8SYBASE.