cancel
Showing results for 
Search instead for 
Did you mean: 

how to retrieve "env-entry" in servlet code

Former Member
0 Kudos

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.

Accepted Solutions (0)

Answers (1)

Answers (1)

SidBhattacharya
Product and Topic Expert
Product and Topic Expert
0 Kudos

1. The order is important so you should have the env-entry as name,value,type and not name,type, value. use the developer studio to enter these values rather than manually doing it.

2. No, you need not give the entire path.

Former Member
0 Kudos

thanks for the hints, but unfortunately they didn't work.

1. after switching the order of value and type in env-entry, rebuild/redeplpoy, same exception. the ordering probably didn't matter since even with the reversed order, the name and value showed up correctly under the jndi tree.

2. well, i tried giving it the full path, starting with 'webContainer', then 'applications' etc, separated by forward slash. now the exception says path to webContainer is not found.

so what gives? are there no standards?