Add Env variable in web application using web.xml

Posted: September 2, 2008 in Uncategorized

How to add veriable/enviorment variabls in web application.these are the variable you can access anywhere in project

here is solution

addfollwing tag to web xm…and given values of your own choics

<env-entry>
    <env-entry-name>webmasterEmail</env-entry-name>
    <env-entry-value>admin@domain.com</env-entry-value>
    <env-entry-type>java.lang.String</env-entry-type>
</env-entry>

you can access in a code by this

// Get a handle to the JNDI environment naming context
Context env = (Context)new InitialContext().lookup("java:comp/env");
// Get a single value
String webmasterEmail = (String)env.lookup("webmasterEmail");

thats It ...enjoyyyyyyyy

here is the helping uRL

http://wiki.metawerx.net/wiki/Web.xml.EnvEntry

comment here if it is useful for you ;) 
Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s