File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Tomcat and the fly likes javax.servlet.ServletException: Name java: is not bound in this Context Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "javax.servlet.ServletException: Name java: is not bound in this Context" Watch "javax.servlet.ServletException: Name java: is not bound in this Context" New topic
Author

javax.servlet.ServletException: Name java: is not bound in this Context

Nagendra Batchu
Ranch Hand

Joined: Jan 23, 2008
Posts: 32
Hi,

I need to get the DB connection object from the data source using tomcat 5.5 server.

1 Step: Added classess12.jar in E:\Tomcat 5.5\common\lib folder
2 Step:Added resource tag in the context.xml file

The context.xml file is as follows:

<Context>

<WatchedResource>WEB-INF/web.xml</WatchedResource>

<Manager pathname="" />
<Resource name="jdbc/myoracle" auth="Container"
type="javax.sql.DataSource" driverClassName="oracle.jdbc.driver.OracleDriver"
url="jdbcracle:thin:@172.18.109.126:1521:CDMSDB"
username="cdmsdvlp" password="cdmsdvlp" maxActive="20" maxIdle="10"
maxWait="-1"/>

</Context>

3 Step: Added resource tag in web.xml , The resource tag is as follows:

<resource-ref>
<description>Oracle Datasource example</description>
<res-ref-name>jdbc/myoracle</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>

4 Step: The following code used in the jsp :

Context initContext = new InitialContext();
Context envContext = (Context)initContext.lookup("java:/comp/env");
DataSource ds = (DataSource)envContext.lookup("jdbc/myoracle");
Connection con = ds.getConnection();

Please help me in solving the above mentioned problem.
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

What does logs says ?


[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Nagendra Batchu
Ranch Hand

Joined: Jan 23, 2008
Posts: 32
In the Logs it displays as

javax.servlet.ServletException: Name java: is not bound in this Context
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:843)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:776)
org.apache.jsp.recieveSMS_jsp._jspService(recieveSMS_jsp.java:368)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:334)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


root cause

javax.naming.NameNotFoundException: Name java: is not bound in this Context
org.apache.naming.NamingContext.lookup(NamingContext.java:769)
org.apache.naming.NamingContext.lookup(NamingContext.java:152)
javax.naming.InitialContext.lookup(Unknown Source)
org.apache.jsp.recieveSMS_jsp._jspService(recieveSMS_jsp.java:67)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:334)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

The code and logs looks OK.
Some doubts:
What is the purpose of adding "class12.jar" into the E:\Tomcat 5.5\common\lib folder ?
Comment out the

Also refer this tomcat doc for the same: http://tomcat.apache.org/tomcat-5.5-doc/jndi-datasource-examples-howto.html
BTW, do you found any logs at the server startup?
Nagendra Batchu
Ranch Hand

Joined: Jan 23, 2008
Posts: 32
Thanks for your reply,

But even if i comment the below lines

<WatchedResource>WEB-INF/web.xml</WatchedResource>

<Manager pathname="" />

still its not working.

Please suggest.



Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Have you tired other options like, Tomcat docs and server startup logs. Some times you won't get the object because the related XML are not well formed.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: javax.servlet.ServletException: Name java: is not bound in this Context
 
Similar Threads
How to: DataSource in tomcat 5 with netBeans 5
Connection pooling in tomcat
Is this true: JNDI equals Connection Pooling
Database connectivity issue
Solution ------ Cannot create JDBC driver of class '' for connect URL 'null'