Link to home
Start Free TrialLog in
Avatar of Mark
Mark

asked on

javax.naming.NameNotFoundException: Name ... is not bound in this Context.

In my Tomcat app I'm getting the message "javax.naming.NameNotFoundException: Name [connURL] is not bound in this Context." I believe I have exactly the same configuration (but apparently not) on a different host and it works fine. My code is:
<%@page import="javax.naming.Context, javax.naming.NamingException" %>
<%
String _dbURL = (String) env.lookup("connURL");
%>

Open in new window

My WEB-INF/web.xml, is:
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
                      http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
  version="3.1"
  metadata-complete="true">

<env-entry>
  <env-entry-name>connURL</env-entry-name>
  <env-entry-value>jdbc:mysql://localhost/members?</env-entry-value>
  <env-entry-type>java.lang.String</env-entry-type>
</env-entry>

</web-app>

Open in new window

As I said, this works on a different host. What is my problem?
Avatar of mccarl
mccarl
Flag of Australia image

Not sure why/how this is working on a different host, but can you try this line instead...

String _dbURL = (String) env.lookup("java:comp/env/connURL");

Open in new window

Avatar of Mark
Mark

ASKER

Thanks for the reply. Nope, didn't work. On browser:
type Exception report

message javax.servlet.ServletException: javax.naming.NameNotFoundException: Name [java:comp/env/connURL] is not bound in this Context. Unable to find [java:comp].

description The server encountered an internal error that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: javax.servlet.ServletException: javax.naming.NameNotFoundException: Name [java:comp/env/connURL] is not bound in this Context. Unable to find [java:comp].
	org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:549)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:455)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
	org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

root cause

javax.servlet.ServletException: javax.naming.NameNotFoundException: Name [java:comp/env/connURL] is not bound in this Context. Unable to find [java:comp].
	org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:906)
	org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:835)
	org.apache.jsp.index_jsp._jspService(index_jsp.java:902)
	org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
	org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

root cause

javax.naming.NameNotFoundException: Name [java:comp/env/connURL] is not bound in this Context. Unable to find [java:comp].
	org.apache.naming.NamingContext.lookup(NamingContext.java:818)
	org.apache.naming.NamingContext.lookup(NamingContext.java:166)
	org.apache.jsp.index_jsp._jspService(index_jsp.java:483)
	org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
	org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

Open in new window

catalina.out:
14-Jun-2016 01:45:17.224 SEVERE [ajp-nio-8009-exec-1] org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [jsp] in context with path [] threw exception [javax.servlet.ServletException: javax.naming.NameNotFoundException: Name [java:comp/env/connURL] is not bound in this Context. Unable to find [java:comp].] with root cause
 javax.naming.NameNotFoundException: Name [java:comp/env/connURL] is not bound in this Context. Unable to find [java:comp].
        at org.apache.naming.NamingContext.lookup(NamingContext.java:818)
        at org.apache.naming.NamingContext.lookup(NamingContext.java:166)
        at org.apache.jsp.index_jsp._jspService(index_jsp.java:483)
        at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
        at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
        at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
        at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:537)
        at org.apache.coyote.ajp.AbstractAjpProcessor.process(AbstractAjpProcessor.java:831)
        at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:658)
        at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1556)
        at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1513)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
        at java.lang.Thread.run(Thread.java:745)

Open in new window

Permission issue on WEB-INF folder?
> ls -ld WEB-INF/
drwxrwS--- 7 horeb horeb 4096 2016-06-13 02:21 WEB-INF//

ls -l WEB-INF/web.xml
-rw-rw---- 1 horeb horeb 14554 Nov  2  2014 WEB-INF/web.xml

/etc/group:
tomcat:x:200:mfoley,cantleys
horeb:x:1000:tomcat,mfoley,daemon

Open in new window

Note that if I make WEB-INF group executable, or change its ownership to tomcat, I get a horrendous  list of 200 errors in catalina.out and tomcat fails to start. I can post those errors if you think it would help.
Avatar of Mark

ASKER

I've changed the WEB-INF directory to have group execute.

> ls -ld WEB-INF/
drwxrws--- 7 horeb horeb 4096 2016-06-14 01:54 WEB-INF/

I can then access files in this directory from the jsp apps, although I still can't get the variable via env.lookup(). However, if I restart tomcat with this setting I get the errors shown below and tomcat fails to start. I can't figure out why have group execute crashes tomcat -- makes no sense. I've not run into this problem on any of about half-a-dozen jsp apps on different hosts I've done in the past. Really need some help figuring this out.
catalina.txt
ASKER CERTIFIED SOLUTION
Avatar of mccarl
mccarl
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mark

ASKER

OK, new question: https://www.experts-exchange.com/questions/28951977/Linux-Apache-Tomcat-doesn't-run-if-WEB-INF-is-listable.html

This does have some problem way deeper than env.lookup(). If WEB-INF is listable, tomcat won't run. Error messages in catalina.out are less than helpful. I've tried everything I can think of. I've even upgraded to a newer version of tomcat. Everything appears identical with the other hosts that do run w/o problem!

I've already spent way too much time on this problem and still no clue whatsoever.
Avatar of Mark

ASKER

I've solved the problem. WEB-INF is back to group listable. I stripped down the app directory's WEB-INF/web.xml file to just the env variables I want and removed all the other entries from the as-shipped web.xml. Tomcat then started just fine and I was able to do the env.lookup("connURL") w/o problem. I confirmed by putting the as-shipped web.xml file back and tomcat failed to start with the usual 200+ inscrutable error messages.

More details available in the answer in question https://www.experts-exchange.com/questions/28951977/Linux-Apache-Tomcat-doesn't-run-if-WEB-INF-is-listable.html