tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Nikola Milutinovic" <Nikola.Milutino...@ev.co.yu>
Subject Re: JNDI - What resources are loaded?
Date Fri, 28 Jun 2002 05:20:22 GMT
> Is there a way to list all of the JNDI Resources that are loaded for a
> particular context? 

Sure.

Here is a snipp from my "JNDI browser" JSP:

<%@ page
  info="JNDI browser"
  import="javax.naming.*, javax.sql.*, java.sql.*"
  contentType="text/html; charset=windows-1250"
%><%!
static public String DEF_CPATH = "java:/";
%><%
//String contextPath = "java:comp/env/jdbc";
String contextPath = request.getParameter( "cpath" );
if( contextPath == null ) {
  contextPath = DEF_CPATH;
}
%>
<html>
<head>
<title>Test - JNDI browser</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1250">
</head>

<body bgcolor="#FFFFFF" text="#000000">
<h1>JNDI browser</h1>
<p>Context looked up: <strong><%= contextPath %></strong></p>
<%
InitialContext initCtx;
Context envCtx;

initCtx = new InitialContext();
if( (envCtx = (Context)initCtx.lookup( contextPath )) == null ) {
  out.println( "<p>No " + contextPath + " context</p>" );
} else {
  NamingEnumeration enum = initCtx.listBindings( contextPath );
  int i = 1;
%>
<table width="100%" border="1" cellspacing="0" cellpadding="3">
  <%
  while( enum.hasMore() ) {
%>
  <tr> 
    <td><%= i %></td>
    <td><%= ((Binding)enum.next()).toString() %></td>
  </tr>
<%
  }
%>
</table>
</body>
</html>

Nix.
Mime
View raw message