-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Anjib,

On 9/8/2011 4:51 PM, Anjib Mulepati wrote:
> DataSource ds = null; try { 40.           Context initCtx = new
> InitialContext(); 41.            Context envCtx = (Context)
> initCtx.lookup("java:comp/env"); 42.           ds = (DataSource)
> envCtx.lookup("jdbc/dynic");

Odd to use a local variable for this, but I guess you could do that.

I've seen "java:comp/env" and "java:/comp/env", but both seem to work.

Try running this JSP. It's a bit fragile, but it should get the job done.

- -chris

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd";>
<%@page pageEncoding="UTF-8"
   session="false"
   language="Java"
   import="
    javax.naming.InitialContext,
    javax.naming.Binding,
    javax.naming.Context,
    javax.naming.NamingEnumeration,
    javax.naming.NamingException
   "
%>
<%
  String path = "java:/comp/env";

  String pathParam = request.getParameter("path");
  if(null != pathParam && !"".equals(pathParam.trim()))
    path = pathParam.trim();

  int pos = path.lastIndexOf('/');
  String parent = pos > 0 ? path.substring(0, pos) : "java:comp/env";
%>
<html xmlns="http://www.w3.org/1999/xhtml"; xml:lang="en" lang="en">
<head>
  <title>JNDI Browser: <%= path %></title>
</head>
<body>
  <h1>JNDI Browser: <%= path %></h1>

  <p><a href="?path=<%= parent %>"><%= parent %></a></p>
<%
  InitialContext ctx = null;
  NamingEnumeration e = null;
  try
  {
    ctx = new InitialContext();
    e = ctx.listBindings(path);

    if(e.hasMoreElements())
    {
%>
  <ul>
<%
      while(e.hasMoreElements())
      {
        Binding b = (Binding)e.next();
%>
    <li>
<%
        if(b.getObject() instanceof Context)
        {
%>
          <a href="?path=<%= path %>/<%= b.getName() %>"><%=
b.getName() %></a>
<%
        }
        else
        {
%>
           <%= b.getName() %> (<%= b.getClassName() %>)
<%
        }
%>
    </li>
<%
      }
%>
  </ul>
<%
    }
    else
    {
%>
  <p>JNDI context is empty</p>
<%
    }
  }
  catch (NamingException ne)
  {
%>
  <p>Error: <%= ne.getMessage() %><pre>
  <%
    java.io.PrintWriter myout = new java.io.PrintWriter(out);
    ne.printStackTrace(myout);
    myout.flush();
  %>
  </pre></p>
<%
  }
  finally
  {
    if(null != e) try { e.close(); } catch (NamingException ne)
      { %><p><%= ne.getMessage() %></p><% }

    if(null != ctx) try { ctx.close(); } catch (NamingException ne)
      { %><p><%= ne.getMessage() %></p><% }
  }//foo
%>
</body>
</html>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk5pL3gACgkQ9CaO5/Lv0PBLAQCglRlAcKBZa5Gtrg494FfcvA2c
/hIAoIu0fj/5ejz3+C3Pk/S8i1PeQG50
=F0ZW
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to