Win a copy of Microservices Testing (Live Project) this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Problem with Return type for LDAP Search

Ranch Hand
Posts: 181
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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

public void doStartSearch(String givenName)throws NamingException{

Attributes matchAttrs = new BasicAttributes(true);

Hashtable env = new Hashtable(5, 0.75f);

env.put(Context.PROVIDER_URL, "ldap://localhost:2389");

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);
NamingEnumeration"dv=address book,o=vds", matchAttrs, attrIDs);

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

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);
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!!
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic