Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Nagendra Batchu
Ranch Hand
Posts: 32
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2905
1
Java Spring Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What does logs says ?
 
Nagendra Batchu
Ranch Hand
Posts: 32
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2905
1
Java Spring Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 32
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2905
1
Java Spring Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic