解决方案 »

  1.   

    把if给成while
    while (answer.hasMoreElements()) {

    String name = "";
    String realName = "";
    String allName = "";
    String departmentName = "";
    String userPrincipalName = "";
    SearchResult sr = null;
    try {
    sr = (SearchResult) answer.next();
    } catch (NamingException e1) {
    e1.printStackTrace();
    }

    if (sr == null) {
    continue;
    }


    Attributes attrs = sr.getAttributes();

    if (attrs == null) {
    continue;
    }

    try {

    System.err.println("==================");
    System.out.println("getname =  " + sr.getName());
    for (NamingEnumeration ne = attrs.getAll(); ne.hasMore();) { Attribute attr = (Attribute) ne.next();
    // 读取属性ID值
    attributeID = attr.getID().toString();
    // 读取属性值
    for (NamingEnumeration e = attr.getAll(); e.hasMore();) {
    attributeValues = e.next().toString();
    } if (attributeID.equals(ADProperty.UserLogonName)) {
    userPrincipalName = attributeValues;
    System.err.println("======getLdapUser userPrincipalName : "+userPrincipalName);
    } if (attributeID.equals(ADProperty.UserLogonName_PRE_WIN2000)) {
    name = attributeValues;
    System.err.println("======getLdapUser name : "+name);
    } if (attributeID.equals(ADProperty.FirstName)) {
    realName = attributeValues;
    } if (attributeID.equals(ADProperty.Department)) {
    departmentName = attributeValues;
    } if (attributeID.equals(ADProperty.AllName)) {
    allName = attributeValues;
    }

    }
    } catch (NamingException e) {
    e.printStackTrace();
    }


    if (userPrincipalName == null || userPrincipalName.length() == 0) {
    System.err.println("userPrincipalName is null ??????");
    continue;
    }

    //添加部门
    departmentNameList.add(departmentName);

    if (realName == null || realName.length() == 0) {
    realName = allName;
    }

    System.out.println("=======11111111="+userPrincipalName.split("@")[0]);
    name=userPrincipalName.split("@")[0];
    userList.add(new User(name, allName, departmentName,User.DominUser));

    }