public final class PagedResultsControl extends BasicControl
下面的代码示例演示如何使用类:
// Open an LDAP association
LdapContext ctx = new InitialLdapContext();
// Activate paged results
int pageSize = 20; // 20 entries per page
byte[] cookie = null;
int total;
ctx.setRequestControls(new Control[]{
new PagedResultsControl(pageSize, Control.CRITICAL) });
do {
// Perform the search
NamingEnumeration results =
ctx.search("", "(objectclass=*)", new SearchControls());
// Iterate over a batch of search results
while (results != null && results.hasMore()) {
// Display an entry
SearchResult entry = (SearchResult)results.next();
System.out.println(entry.getName());
System.out.println(entry.getAttributes());
// Handle the entry's response controls (if any)
if (entry instanceof HasControls) {
// ((HasControls)entry).getControls();
}
}
// Examine the paged results control response
Control[] controls = ctx.getResponseControls();
if (controls != null) {
for (int i = 0; i < controls.length; i++) {
if (controls[i] instanceof PagedResultsResponseControl) {
PagedResultsResponseControl prrc =
(PagedResultsResponseControl)controls[i];
total = prrc.getResultSize();
cookie = prrc.getCookie();
} else {
// Handle other response controls (if any)
}
}
}
// Re-activate paged results
ctx.setRequestControls(new Control[]{
new PagedResultsControl(pageSize, cookie, Control.CRITICAL) });
} while (cookie != null);
// Close the LDAP association
ctx.close();
...
实现分页结果中定义的控制这类RFC 2696 LDAPv3。控件的值有以下ASN. 1定义:
realSearchControlValue ::= SEQUENCE {
size INTEGER (0..maxInt),
-- requested page size from client
-- result set size estimate from server
cookie OCTET STRING
}
PagedResultsResponseControl
,
Serialized Form
Modifier and Type | Field and Description |
---|---|
static String |
OID
分页的结果控制分配的对象标识符是1.2.840.113556.1.4.319。
|
criticality, id, value
CRITICAL, NONCRITICAL
Constructor and Description |
---|
PagedResultsControl(int pageSize, boolean criticality)
构造一个控件,以设置要返回的结果的每一页的条目数量。
|
PagedResultsControl(int pageSize, byte[] cookie, boolean criticality)
构造一个控件,以设置要返回的结果的每一页的条目数量。
|
public static final String OID
public PagedResultsControl(int pageSize, boolean criticality) throws IOException
pageSize
-参赛人数在一页返回。
criticality
-如果真那么服务器必须控制和返回搜索结果由PageSize或拒绝执行搜索。如果是错误的,那么服务器就不需要控制了。
IOException
如果编码提供的参数到控制时出错。
public PagedResultsControl(int pageSize, byte[] cookie, boolean criticality) throws IOException
一系列的分页结果可以通过设置为零,设置cookie从服务器接收到的最后一块饼干了。
pageSize
-参赛人数在一页返回。
cookie
-可能为空的服务器生成的Cookie。
criticality
-如果真那么服务器必须控制和返回搜索结果由PageSize或拒绝执行搜索。如果是错误的,那么服务器就不需要控制了。
IOException
如果编码提供的参数到控制时出错。
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.