| 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="jdbc racle: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: 2896
|
|
|
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: 2896
|
|
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: 2896
|
|
|
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.
|
 |
 |
|
|
subject: javax.servlet.ServletException: Name java: is not bound in this Context
|
|
|