Adding a Resource Reference to a Web Application

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:

To add a resource reference:

  1. Select web.xml in the WorkSpace Navigator of the Web Application Development perspective.

    The web.xml editor opens.

  2. 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.

  3. Click Add.

    A new resource is added to the Resource References list with the default name New ResourceRefx.

  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, typejdbc/MyDatabase in the Name field.

  5. Click the arrow in the Type field to open the drop-down list and select one of the following

    Resource types

    TypeUse 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 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.

  7. 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.

  8. (Optional) Type a description for the resource in the Description field.

  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.

    Resource links

    TypeLink
    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.

Developing a Web Application

Configuring the web xml File

Web.xml Editor

WorkSpace Navigator

Web Application Development Perspective

Send your feedback on this help topic to Sybase Tech Pubs: pubs@sybase.com