![]() |
![]() |
||||
This tag provides environment variables (properties) which can be accessed by your web application using JNDI.
See advantages of specifying parameter values in web.xml for reasons you would want to use this tag.
Env entries are similar to providing init-params for a servlet or filter, or context-params for your application, except they use JNDI.
A single <env-entry> tag is used for each property.
The property name and value are set using <env-entry-name> and <env-entry-value>. <env-entry-type> is used to specify the datatype, which is usually java.lang.String. This can be any fully qualified class name, as long as the class has a constructor that accepts a single string.
The following example is an entry named "webmasterEmail". This might be used to send administrative alerts, such as error dumps from a custom error page.
<env-entry> <env-entry-name>webmasterEmail</env-entry-name> <env-entry-type>java.lang.String</env-entry-type> <env-entry-value>admin@domain.com</env-entry-value> </env-entry>
To access the properties from your Java/JSP code, use the following syntax:
// Get a handle to the JNDI environment naming context
|
As with all JNDI names, the <env-entry-name> can be a path instead of a single name. For example:
<env-entry-name>defaults/alerts/webmasterEmail</env-entry-name>