我正在制作一个 LDAP 搜索应用程序。它工作正常,但在搜索结果中,它也给了我字段名称
前任:
**sn:** YYYY
**department:** xxxx
....etc
如何避免打印字段名称?
谢谢
public LdapContext getLdapContext() {
LdapContext ctx = null;
try {
Hashtable<String, String> env = new Hashtable<String, String>();
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.SECURITY_AUTHENTICATION, "XXX");
env.put(Context.SECURITY_PRINCIPAL, "XXXX");
env.put(Context.SECURITY_CREDENTIALS, "XXXX");
env.put(Context.PROVIDER_URL, "XXXXX");
ctx = new InitialLdapContext(env, null);
System.out.println("Connection Successful.");
} catch (NamingException nex) {
System.out.println("LDAP Connection: FAILED");
nex.printStackTrace();
}
return ctx;
}
SearchControls constraints = new SearchControls();
constraints.setSearchScope(SearchControls.SUBTREE_SCOPE);
String[] attrIDs = { lastName, firstName, location,
telephoneNumber, jobTitle, division };
constraints.setReturningAttributes(attrIDs);
// First input parameter is search base, it can be
// "CN=Users,DC=Domain,DC=com"
// Second Attribute can be uid=username
NamingEnumeration<SearchResult> answer = ctx.search("OU= Users,DC=Domain,DC=com",
"sn=" + lastname, constraints);
一些代码来显示我在做什么,,,请帮忙