escapingdns.java
来自「JAVA 工作指南 可以说是程序员必备的东西哦」· Java 代码 · 共 35 行
JAVA
35 行
import javax.naming.ldap.*;
import javax.naming.*;
/*
* Shows how to format DNs with special characters by escaping
* the values
*/
public class EscapingDNs {
public static void main(String args[]) {
try {
// DN with ',' (comma) in its attribute value
String unformatted = "Juicy, Fruit";
String formatted = Rdn.escapeValue(unformatted);
LdapName dn = new LdapName("cn=" + formatted);
System.out.println("dn:" + dn);
// DN with a '+' (plus) in its attribute value
unformatted = "true+false";
formatted = Rdn.escapeValue(unformatted);
dn = new LdapName("cn=" + formatted);
System.out.println("dn:" + dn);
// DN with a binary value as its attribute value
byte[] bytes = new byte[] {1, 2, 3, 4};
formatted = Rdn.escapeValue(bytes);
System.out.println("Orig val: " + bytes +
" Escaped val: " + formatted);
} catch (InvalidNameException e) {
e.printStackTrace();
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?