Chapter 25. Using JNDI and Enterprise JavaBeans

Introduction

The Java Naming and Directory Interface (JNDI) is an API that Java developers use to access naming and directory services. These services are technologies that Java programs use to store or bind objects for later use, as well as search for or “look up” object references. The purpose of JNDI is to separate the responsibility of maintaining a repository of commonly used objects from the wide variety of Java classes that use those objects, including servlets and JSPs.

Examples of JNDI services are the Remote Method Invocation registry and the Lightweight Directory Access Protocol (LDAP). The JNDI API, represented by the javax.naming package, provides a common implementation for accessing objects that are bound to these services.

Tip

The javax.naming package is part of the Java 2 1.3 and 1.4 Software Development Kits (SDKs).

Each of these technologies has a naming scheme with which “JNDI objects” can be found. The structure of these schemes is often hierarchical; you start at the top of the JNDI tree, then work your way down to each of the branches to find what you are looking for. Using JNDI, Java programs begin with an "initial context,” similar to the forward slash (/) from which Unix begins to describe the location of a file. The / represents the root of a storage medium or hard disk; you can find the Users folder at the top level of the disk by entering /Users.

In Tomcat, the initial context of its built-in JNDI implementation ...

Get Java Servlet & JSP Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.