Skip to Content
0
Former Member
Oct 14, 2004 at 10:05 PM

how to retrieve "env-entry" in servlet code

100 Views

i have a pretty straight-forward web app, which contains a servlet, among other things. the web app is packaged in .war, and it in turn is part of a .ear file. i am using WAS 640 sneak preview on windows xp.

in the web.xml file, i added the following lines:

<env-entry>

<description>some texts</description>

<env-entry-name>myapp.home</env-entry-name>

<env-entry-type>java.lang.String</env-entry-type>

<env-entry-value>c:/myapp</env-entry-value>

</env-entry>

in my servlet code, i try to retrieve the value for "myapp.home" like this:

try

{

Context ctx = new InitialContext();

home = (String) ctx.lookup("java:comp/env/myapp.home");

} catch (Exception ex) {

ex.printStackTrace();

}

after .ear is deployed, i can see in the JDNI Registry (using Visual Admin Tool), myapp.home is added to the tree:

webContainer

-applications

--myCompany.com

---myEarFileName

-


myWebAppRoot

-


java:comp

-


env

-


myapp.home

the entry has the correct class name and object value.

when the servlet code that performs the jndi lookup is called, i get an exception:

com.sap.engine.services.jndi.persistent.exceptions.NameNotFoundException: Path to object does not exist at : java:comp

??? QUESTIONS:

#1 what am i doing wrong?

#2 if the lookup name must contain the entire jndi tree as listed above, then how can this code be portable to other app servers?

thoughts are greatly appreciated.