Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

newbie: context.xml and web.xml

843838Dec 14 2005 — edited Dec 15 2005
Hi all,
I'm kind of new to Java web apps, and I'd like to know the difference between context.xml and web.xml. Specifically when talking about data sources, and whether both files are 'generic', i.e. not webServer-dependent. For example, do all web servers look for META-INF/context.xml and WEB-INF/web.xml or do they have different files with different contents? I don't know the target web server of my app, so it's really important I provide whatever's necessary to work on most web servers...

Example:
In my app, I have a file called 'META-INF/context.xml' in which I declared a <Resource> under the name 'jdbc/myDSN'. My test web app simply lists the bindings under java:comp/env, just to make sure that the path jdbc/myDSN exists.
Under Tomcat, it exists.
Under WebLogic, it doesn't exist.

I did some readind, and it appears that if I add a <resource-ref> for the above name in my WEB.XML file, my app successfully detects the jdbc/myDSN path under WebLogic, BUT: when I do the lookup() for 'jdbc/myDSN', I get an exception:

javax.naming.LinkException: [Root exception is javax.naming.NameNotFoundException: While trying to lookup 'jdbc.myDSN' didn't find subcontext 'jdbc'

How do I make sure everything works ok on WebLogic as well as Tomcat????
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 12 2006
Added on Dec 14 2005
2 comments
320 views