title: Context specific JNDI parameters problem in tomcat 6
body: <p>I am having trouble using JNDI when two or more applications are deployed on Tomcat 6.
  Consider the following scenario:
  I have 2 webapps, where each web.xml contains one JNDI parameter.<br/><br/>
  web.xml webapp A:<br/>
  <code><br/>
  <code>&lt;env-entry&gt;</code><br/>
  <code>&lt;env-entry-name&gt;testEntry&lt;/env-entry-name&gt;</code><br/>
  <code>&lt;env-entry-value&gt;value A&lt;/env-entry-value&gt;</code><br/>
  <code>&lt;env-entry-type&gt;java.lang.String&lt;/env-entry-type&gt;</code><br/>
  <code>&lt;/env-entry&gt;</code><br/>
  </code></p>
  
  <p>web.xml webapp B:<br/>
  <code><br/>
  <code>&lt;env-entry&gt;</code><br/>
  <code>&lt;env-entry-name&gt;testEntry&lt;/env-entry-name&gt;</code><br/>
  <code>&lt;env-entry-value&gt;value B&lt;/env-entry-value&gt;</code><br/>
  <code>&lt;env-entry-type&gt;java.lang.String&lt;/env-entry-type&gt;</code><br/>
  <code>&lt;/env-entry&gt;</code><br/>
  </code></p>
  
  <p>When I deploy both webapps and lookup the value for testEntry, <strong>both</strong> webapps return value A. It seems only the JNDI params from the first loaded web.xml are available.
  Accoring to my understanding of JNDI, each web.xml contains webapp specific JNDI values that are only available in their own respective context. What am I doing/thinking wrong here?</p>
  
  <p>This leads to my next question. Howto define global JNDI parameters that are available in all contexts? In the tomcat docs I've read that you should use {CATALINA_HOME}/conf/context.xml for this purpose. But the environment entries are not available inside the contexts. Placing them in {CATALINA_HOME}/conf/web.xml makes them globally accessible, but I doubt this is the correct way.</p>
  
  <p>This is my Java code to look them up:<br/><br/>
  <code>
  Context initCtx = new InitialContext();<br/>
  Context envCtx = (Context) initCtx.lookup("java:comp/env");<br/>
  String value = (String)envCtx.lookup("testEntry");<br/>
  </code></p>
  
  <p>Any help would be welcome, because good documentation on JNDI is scars.</p>