Adding an EJB Reference to a Web Application

Servlets and JSPs use EJB references to instantiate proxies for EJB home interfaces. EJB references must be cataloged in the deployment descriptor so the Web application can run independent of a specific naming configuration. When deploying the Web application, a site administrator can map site-specific EJB JNDI names to the references used by the Web application.

Servlets and JSPs can look up an EJB by specifying the reference name prefixed with java:comp/env/. For example, if you enter ejb/catalog in EAServer Manager, use java:comp/env/ejb/catalog in your JSP or servlet source code.

To add an EJB reference:

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

    The web.xml editor opens,

  2. Select the EJB tab of the editor.

    EJB References and EJB Local References sections appear.

  3. Expand EJB References.

    A list of defined references is displayed.

  4. To add a new reference, click Add.

    General Information displays to the right of the references section.

  5. Change the default EJB name in the Name field of the General Information section.

    The name specifies the JNDI name used in your code to refer to the called EJB. The aliased name is displayed in the Link Value field. Enter the part of the JNDI name that begins with ejb/. For example, if your code refers to java:comp/env/ejb/MyBean, type ejb/MyBean.

  6. (Optional) Type a link in the Link field.

  7. Click the arrow in theType field to open the drop-down list and select either Entity for entity beans or Session for session beans.

  8. Click Browse adjacent to the Home field and select the Java class name of the EJB remote interface, specified in dot notation

    Example: com.sybase.MyBeanHome.

  9. Click Browse adjacent to the Remote field and select the Java class name of the EJB home interface, specified in dot notation.

    Example: com.sybase.MyBeanRemote.

  10. (Optional) Type a description of the EJB reference.

  11. (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 the actual JNDI name EJB component that is installed in the server where your component, Web application, or application client is to be deployed. This is specified by the JNDI Name property in the Component Properties of the called EJB component.

Developing a Web Application

Web xml Editor

WorkSpace Navigator

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