📄 helloejbclient.java
字号:
/*
*
* Copyright 2002 Author,Zhang Hongzhan. All Rights Reserved.
*
* This software is the proprietary information of Author.
*
*/
package helloejb;
import java.math.BigDecimal;
import java.rmi.RemoteException;
import java.util.Properties;
import javax.ejb.CreateException;
import javax.ejb.RemoveException;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.rmi.PortableRemoteObject;
public class HelloEJBClient {
private static final String JNDI_NAME = "HelloEJB";
private static final String url = "t3://localhost:7001";
public static void main(String[] args) {
try{
// Get an InitialContext
Properties env = new Properties();
env.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
env.put(Context.PROVIDER_URL, url);
Context ctx = new InitialContext(env);
Object h=ctx.lookup(JNDI_NAME);
HelloEJBHome home=(HelloEJBHome)PortableRemoteObject.narrow(h,
HelloEJBHome.class);
HelloEJBRemote currencyHelloWorld =home.create();
String hello=currencyHelloWorld.HelloWorld();
System.out.println("My EJB said:"+hello);
BigDecimal param = new BigDecimal ("100.00");
BigDecimal amount = currencyHelloWorld.dollarToRMB(param);
System.out.println("100 dollar = "+amount+" RMB");
amount = currencyHelloWorld.poundToRMB(param);
System.out.println("100 pound = "+amount+" RMB");
System.exit(0);
}catch(Exception ex) {
System.err.println("Caught an unexpected exception!");
ex.printStackTrace();
}
}
private static void log(String s) {
System.out.println(s);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -