This week's book / license giveaways are in the JDBC and Relational Databases and Java in General forums.
We're giving away four copies each of PostGIS in Action and Java Advanced Topics Training and have the authors on-line!
See this thread and this one for details.
The moose likes Tomcat and the fly likes JNDI in entry in context.xml and web.xml Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Products » Tomcat
Bookmark "JNDI in entry in context.xml and web.xml" Watch "JNDI in entry in context.xml and web.xml" New topic

JNDI in entry in context.xml and web.xml

ani bua

Joined: Mar 06, 2009
Posts: 22
Hi all,
I am using Data base connection pooling . I am using a JNDi lookup from my code .

I am making the following entry in web.xml
<description>My Connection</description>
Also putting the following entry in the conext.xml

url="<some db url>"

And i am a using the following java code fro accessing the JNDI resource

Context ctx = new InitialContext();
ds =(DataSource) ctx.lookup("java:comp/env/jdbc/TestDB");
conn = ds.getConnection();

Now the problem is if I comment the web.xml entry then the code is still running Then what is the use of putting it in web.xml ???
Thanks in advance.
Misha Ver
Ranch Hand

Joined: Mar 03, 2008
Posts: 470
Did you have a chance to restart Tomcat after the change?
ani bua

Joined: Mar 06, 2009
Posts: 22
Yes i have restarted the tomcat but still there is no change.eans if i comment the web.xml entry it is still running.
ani bua

Joined: Mar 06, 2009
Posts: 22
I just want to know how the resource reference in web.xml is reffered to context.xml .Means how are my java code JNDI lookup,web.xml entry and the context entry work togather.If any one can tell me I will be very thankful.It is urgent.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16600

If you'll notice, the web.xml entry defines the data type and other J2EE-specific attributes. While Tomcat may be able to get by without the web.xml entry - at least in certain cases - that's no guarantee that all J2EE servers will be able to do so or that future Tomcat releases will be able to do so. For example, Tomcat6 yells at me when I define session objects that aren't serializable, but none of the earlier versions of Tomcat did.

Customer surveys are for companies who didn't pay proper attention to begin with.
ani bua

Joined: Mar 06, 2009
Posts: 22
Then how the flow use to continue . The lookup i use in code taken from where ???
amit punekar
Ranch Hand

Joined: May 14, 2004
Posts: 535
Check Setting up Tomcat Connection Pool

I agree. Here's the link:
subject: JNDI in entry in context.xml and web.xml