⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 getserverdateejbclient.java

📁 J2EE上课详细课件,精通J2EE编程教程.
💻 JAVA
字号:
package j2ee.client;

import java.rmi.RemoteException;
import java.util.Hashtable;
import javax.ejb.CreateException;
import javax.naming.InitialContext;
import javax.naming.NamingException;
//测试EJB的远程客户端
public class getServerDateEJBClient {
	//得到Home接口
	private j2ee.ejb.getServerDateStatelessHome getHome()
			throws NamingException {
		return (j2ee.ejb.getServerDateStatelessHome) getContext().lookup(
				j2ee.ejb.getServerDateStatelessHome.JNDI_NAME);
	}
	//得到初始化上下文
	private InitialContext getContext() throws NamingException {
		Hashtable props = new Hashtable();
		props.put(InitialContext.INITIAL_CONTEXT_FACTORY,
				"weblogic.jndi.WLInitialContextFactory");
		props.put(InitialContext.PROVIDER_URL, "t3://127.0.0.1:7001");
		InitialContext initialContext = new InitialContext(props);
		return initialContext;
	}
	//测试业务逻辑的方法
	public void testBean() {
		try {
			j2ee.ejb.getServerDateStateless myBean = getHome().create();
			System.out.println(myBean.getServerDateString());
		} catch (RemoteException e) {
			e.printStackTrace();
		} catch (CreateException e) {
			e.printStackTrace();
		} catch (NamingException e) {
			e.printStackTrace();
		}
	}
	//主方法
	public static void main(String[] args) {
		getServerDateEJBClient test = new getServerDateEJBClient();
		test.testBean();
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -