LDAP error code 2 - paged results cookie is invalid Java 代码解决
这个错误通常是由于分页搜索操作返回的cookie无效而导致的。要解决此问题,可以使用以下Java代码:
- 在分页搜索操作中设置cookie:
Control[] controls = new Control[] { new PagedResultsControl(pageSize, cookie, Control.CRITICAL) };
SearchResult searchResult = ctx.search(searchBase, searchFilter, searchCtls.add(controls));
- 在处理分页搜索结果时,检查返回的cookie是否有效:
Control[] responseControls = searchResult.getResponseControls();
if (responseControls != null) {
for (int i = 0; i < responseControls.length; i++) {
if (responseControls[i] instanceof PagedResultsResponseControl) {
PagedResultsResponseControl prrc = (PagedResultsResponseControl) responseControls[i];
cookie = prrc.getCookie();
}
}
}
if (cookie != null) {
// 处理下一页搜索结果
}
通过这种方法,您可以确保使用有效的cookie进行分页搜索操作,从而避免LDAP错误代码2的问题。
原文地址: https://www.cveoy.top/t/topic/bEJk 著作权归作者所有。请勿转载和采集!