Here's a trivial example (and please excuse the sloppiness)--
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<%@ page import="javax.naming.*, javax.naming.directory.*, java.util.Properties" %>
<%@ page import="java.util.Hashtable, java.util.Enumeration, java.io.*" %>
<HTML>
<HEAD>
<LINK REL=StyleSheet HREF="./css/general.css" TYPE="text/css"
TITLE="tagtraum-style">
</HEAD>
<body bgcolor="#FFFFFF" text="#003366" link="#336699" vlink="#996666"
alink="#FFCC66">
<% for (int i=1;i<5;i++) {%>
<h<%= i %>>Hello, World</h<%= i %>>
<% } %>
<H2>Now let's get some data from the radiator LDAP directory . . .</H2>
<% Attributes attribs = null;
NamingEnumeration names = null;
DirContext dctx = null;
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://radiator.usitc.gov:389/o=U.S.
Government,c=US");
SearchControls ctls = new SearchControls();
String scope = "ou=Operations,ou=International Trade Commission";
SearchResult item;
Attribute mail, phone, title;
NamingEnumeration attrvals;
String pstring;
try {
dctx = new InitialDirContext(env);
names = (NamingEnumeration)dctx.search(scope, "(objectclass=person)", ctls);
try {
if ((names != null) && names.hasMore()) {
int i=0;
%>
<TABLE>
<TH></TH><TH>Name</TH><TH>Description</TH><TH>E-Mail</TH>
<%
while (names.hasMore()) { i++;
item = (SearchResult)names.next();
attribs = item.getAttributes();
%>
<TR>
<TD><%= i %></TD><TD><%= item.getName() %></TD>
<% phone = attribs.get("comment");
attrvals = phone.getAll();
pstring = "";
while (attrvals.hasMore()) pstring = pstring + attrvals.next();
%>
<TD><%= pstring %></TD>
<% mail = attribs.get("mail");
attrvals = mail.getAll();
pstring = "";
while (attrvals.hasMore()) pstring = pstring + attrvals.next();
%>
<TD><%= pstring %></TD>
<%
} // End while clause
%> </TR></TABLE> <%
} // End if clause
else {
System.out.println("No more person items in scope" + scope);
} // End else clause
} // End try
catch (NamingException e) {
e.printStackTrace();
} // End catch NamingException
catch (Exception ex) {
ex.printStackTrace();
} // End catch general exception
dctx.close();
} catch (Exception e) { System.out.println("No person objects found in " +
scope); }
%>
Martin
Jason Cheek wrote:
> I am new to Java but here is what has worked for me.
> I am using the Netscape SDK for Java to access our Netscape Directory
> server. This includes code samples and several beans to do the work for you.
> http://developer.netscape.com/tech/directory/index.html?content=downloads.ht
> ml
> For the book readers out there:
> I have found the "LDAP Programming with Java" book (ISBN: 0201657589), by
> Rob Weltman and Tony Dahbura, to be very helpful with using the SDK.
>
> Regards,
> Jason
>
> -----Original Message-----
> From: Louis [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, October 25, 2000 7:16 AM
> To: [EMAIL PROTECTED]
> Subject: JSP & LDAP
>
> Hi,
> I just install Netscape Directory server with the sample database. Is
> there anyone can provide a sample jsp code which can connect to ldap?
>
> Thanks
>
> Louis
>
> ===========================================================================
> To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
> JSP-INTEREST".
> Some relevant FAQs on JSP/Servlets can be found at:
>
> http://java.sun.com/products/jsp/faq.html
> http://www.esperanto.org.nz/jsp/jspfaq.html
> http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
> http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets
>
> ===========================================================================
> To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
> Some relevant FAQs on JSP/Servlets can be found at:
>
> http://java.sun.com/products/jsp/faq.html
> http://www.esperanto.org.nz/jsp/jspfaq.html
> http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
> http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets