【发布时间】:2015-07-23 10:47:23
【问题描述】:
我需要一些帮助。我必须将整个 jndi db 选项检索到 html 文件中的选择列表中,这意味着我需要访问所有 jndi db 名称并获取这些值 任何想法 ?
【问题讨论】:
我需要一些帮助。我必须将整个 jndi db 选项检索到 html 文件中的选择列表中,这意味着我需要访问所有 jndi db 名称并获取这些值 任何想法 ?
【问题讨论】:
在我的一台 WebLogic 服务器中查找 JNDI 名称时遇到了一些麻烦。我创建了一个遍历 JDNI 树结构并将它们全部打印到控制台的方法。我不确定这是否是您需要的,但这是我使用的代码:
private void printList(String directory){
try {
NamingEnumeration<NameClassPair> namings = context.list(directory);
System.out.println("************Printing " + directory + "**************");
while(namings.hasMoreElements()){
if(directory.equals("")) printList(namings.next().getName());
else printList(directory+"."+namings.next().getName());
}
System.out.println("Done printing " + directory);
} catch (NamingException e) {
// TODO Auto-generated catch block
System.out.println(directory);
}
}
如果您想要根目录中的所有元素,您可以传递所需目录的字符串或空字符串。您需要导入javax.naming.*(或-NamingEnumeration/-NameClassPair)
差点忘了: 您首先需要为方法应在何处查找目录定义一个上下文:
Context context = null;
Hashtable<String, String> ht = new Hashtable<String, String>();
ht.put(Context.PROVIDER_URL, "your_host");
ht.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
//this above needs to be changed to fit your desired system
ht.put(Context.SECURITY_PRINCIPAL, "your_user");
ht.put(Context.SECURITY_CREDENTIALS, "your_password");
try {
context = new InitialContext(ht);
// Use the context in your program
}
catch (NamingException e) {
e.printStackTrace();
}
【讨论】: