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).
Example
<env-entry>
<description>DNS Database Connection DriverName</description>
<env-entry-name>driver</env-entry-name>
<env-entry-value>com.microsoft.jdbc.sqlserver.SQLServerDriver</env-entry-value>
<env-entry-type>java.lang.String</env-entry-type>
</env-entry>
<env-entry>
<description>DNS Pagination of home products</description>
<env-entry-name>page/home</env-entry-name>
<env-entry-value>16</env-entry-value>
<env-entry-type>java.lang.Integer</env-entry-type>
</env-entry>
Each <description>DNS Database Connection DriverName</description>
<env-entry-name>driver</env-entry-name>
<env-entry-value>com.microsoft.jdbc.sqlserver.SQLServerDriver</env-entry-value>
<env-entry-type>java.lang.String</env-entry-type>
</env-entry>
<env-entry>
<description>DNS Pagination of home products</description>
<env-entry-name>page/home</env-entry-name>
<env-entry-value>16</env-entry-value>
<env-entry-type>java.lang.Integer</env-entry-type>
</env-entry>
Code shows to accesses the environment entries
import java.io.*;
import javax.naming.*;
try
{
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){)
import javax.naming.*;
try
{
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:
Post a Comment