aspose file tools
The moose likes EJB and other Java EE Technologies and the fly likes Problem with Return type for LDAP Search Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Reply Bookmark "Problem with Return type for LDAP Search" Watch "Problem with Return type for LDAP Search" New topic
Author

Problem with Return type for LDAP Search

Tauri Valor
Ranch Hand

Joined: Aug 03, 2005
Posts: 166
Hi

I have a problem with the return type for the following code. I wanted to return the "cn" value from this method, when called from a jsp to print in a jsp file.
what should be the return type for my method to retrieve the value in jsp.

The following is my code in Search.java:




public void doStartSearch(String givenName)throws NamingException{

Attributes matchAttrs = new BasicAttributes(true);

Hashtable env = new Hashtable(5, 0.75f);
env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");

env.put(Context.PROVIDER_URL, "ldap://localhost:2389");
System.out.println("Connected");


DirContext ctx = new InitialDirContext(env);
//String[] attrIDs = {"cn","mail","telephoneNumber"};
// ignore case
String[] attrIDs = {"cn"};
matchAttrs.put(new BasicAttribute("givenName",givenName));
SearchControls constraints = new SearchControls();
constraints. setReturningObjFlag (true);
constraints.setSearchScope(SearchControls.SUBTREE_SCOPE);
NamingEnumeration results=ctx.search("dv=address book,o=vds", matchAttrs, attrIDs);

while (results != null && results.hasMore()) {
System.out.println("In while()........");
SearchResult si = (SearchResult) results.next();

System.out.println("name: " + si.getName());
Attributes attrs = si.getAttributes();
if (attrs == null) {
System.out.println("No attributes");
} else {

for (NamingEnumeration ae = attrs.getAll();ae.hasMoreElements() {
Attribute attr = (Attribute) ae.next();
String attrId = attr.getID();
System.out.println("attrId: " + attrId);

for(Enumeration vals = attr.getAll();vals.hasMoreElements() {
System.out.println(attrId+ ": " + vals.nextElement());
//System.out.println("vals.nextElement(): " + vals.nextElement());
}

}

}

}

//return results;


}



Thanks for any help!!
Sud


A Moment's insight is sometimes worth a Life's experience.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem with Return type for LDAP Search
 
Similar Threads
LDAP and NamingEnumeration
How to get entries in ldap?
How to get this specific list from an LDAP Server?
Need a simple Java LDAP client
LDAP sample program