serving the solutions day and night


Monday, September 27, 2010

Java Naming and Directory Interface (JNDI) with Environment Variables

The environment allows you to define your variables name, value and type. At runtime the environment values are not allowed to modify.

Declared the environment variables using the <env-entry> tag in the deployment descriptor (WEB-INF/web.xml in Tomcat). The elements of the <env-entry> tag are:
* <description>: an optional description.
* <env-entry-name>: the entry name.
* <env-entry-value>: a value.
* <env-entry-type>: the java variable type(Boolean, Byte, Double, Character, Float, Integer, Long, Short, String).

  <description>DNS Database Connection DriverName</description>

  <description>DNS Pagination of home products</description>
Each tag describes a single environment entry. In this example, two environment entries have been defined.

Code shows to accesses the environment entries
import javax.naming.*;
Context initCtx = new InitialContext();
Context envCtx = (Context)initCtx.lookup("java:comp/env");
String DRIVER = (String) envCtx.lookup("driver");
Integer PAGINATION_HOME= (Integer) envCtx.lookup("page/home");
catch (Exception e){)

No comments: