解决方案 »

  1.   

    把查询的代码贴出来  public void Ldapbyuserinfo(String userName) {// Create the search controlsSearchControls searchCtls = new SearchControls();// Specify the search scopesearchCtls.setSearchScope(SearchControls.SUBTREE_SCOPE);// specify the LDAP search filterString searchFilter = "sAMAccountName=" + userName;// Specify the Base for the search 搜索域节点String searchBase = "DC=example,DC=COM";int totalResults = 0;String returnedAtts[] = { "url", "whenChanged", "employeeID", "name","userPrincipalName", "physicalDeliveryOfficeName","departmentNumber", "telephoneNumber", "homePhone", "mobile","department", "sAMAccountName", "whenChanged", "mail" }; // 定制返回属性searchCtls.setReturningAttributes(returnedAtts); // 设置返回属性集// searchCtls.setReturningAttributes(null); // 不定制属性,将返回所有的属性集try {NamingEnumeration answer = dc.search(searchBase, searchFilter,searchCtls);if (answer == null || answer.equals(null)) {System.out.println("answer is null");} else {System.out.println("answer not null");}while (answer.hasMoreElements()) {SearchResult sr = (SearchResult) answer.next();System.out.println("************************************************");System.out.println("getname=" + sr.getName());Attributes Attrs = sr.getAttributes();if (Attrs != null) {try {for (NamingEnumeration ne = Attrs.getAll(); ne.hasMore();) {Attribute Attr = (Attribute) ne.next();System.out.println("AttributeID="+ Attr.getID().toString());// 读取属性值for (NamingEnumeration e = Attr.getAll(); e.hasMore(); totalResults++) {String user = e.next().toString(); // 接受循环遍历读取的userPrincipalName用户属性System.out.println(user);}// System.out.println(" ---------------");// // 读取属性值// Enumeration values = Attr.getAll();// if (values != null) { // 迭代// while (values.hasMoreElements()) {// System.out.println(" 2AttributeValues="// + values.nextElement());// }// }// System.out.println(" ---------------");}} catch (NamingException e) {System.err.println("Throw Exception : " + e);}}}System.out.println("Number: " + totalResults);} catch (Exception e) {e.printStackTrace();System.err.println("Throw Exception : " + e);}} 更多的可以去看  http://bbs.it-home.org/thread-1819-1-1.html
     现在想知道的是怎么精确到一个ou目录 查询下面的所有人员,求救
      

  2.   

    去年的贴子,估计你也解决了,给别人看吧。正解是:searchFilter ="objectClass=*";