📄 jndi.java
字号:
package jndi;import javax.naming.*;import java.util.Hashtable;class JNDI { static Context ctx = null; public JNDI() { } public static void bind(String name, String object) { Hashtable ht = new Hashtable(); ht.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory"); ht.put(Context.PROVIDER_URL, "t3://localhost:7001"); try { ctx = new InitialContext(ht); // Use the context in your program ctx.rebind(name, object); } catch (NamingException e) { // a failure occurred System.out.println(e); } finally { try { ctx.close(); } catch (Exception e) { e.printStackTrace(); } } } public static Object lookUp(String name) { Hashtable ht = new Hashtable(); ht.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory"); ht.put(Context.PROVIDER_URL, "t3://localhost:7001"); try { ctx = new InitialContext(ht); // Use the context in your program Object object = ctx.lookup(name); return object; } catch (NamingException e) { e.printStackTrace(); } finally { try { ctx.close(); } catch (Exception e) { // a failure occurred System.out.println(e); } } return null; } public static void main(String args[]) { String arg = args[0]; if(arg.equals("bind")){ System.out.println("bind begin..."); String bookName = "WebLogic introduction"; bind("bookname", bookName); System.out.println("bind end"); } if(arg.equals("lookup")){ System.out.println("lookup begin..."); String bookName; bookName = (String)lookUp("bookname"); System.out.println("bookname is: "+bookName); System.out.println("lookup end"); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -