📄 simpleclient.java
字号:
package client;
import agency.*;
import javax.ejb.*;
import javax.naming.*;
import java.rmi.*;
import javax.rmi.*;
import java.util.*;
public class SimpleClient
{
private static String agencyJNDI = "java:comp/env/ejb/Agency";
public static void main(String[] args) {
if (args.length == 1)
agencyJNDI = args[0];
else if (args.length > 1) {
System.err.println("Usage: SimpleClient [ AgencyJNDI ]");
System.exit(1);
}
try {
InitialContext ic = new InitialContext();
Object lookup = ic.lookup(agencyJNDI);
AgencyHome home = (AgencyHome)PortableRemoteObject.narrow(lookup, AgencyHome.class);
Agency agency = home.create();
System.out.println("Welcome to: "+agency.getAgencyName());
System.out.println("Customer list: "+agency.getAgencyName());
Collection customers = agency.getCustomers();
Iterator it = customers.iterator();
while (it.hasNext())
{
String name = (String)it.next();
System.out.println(name);
}
System.out.println("\nDone\n");
agency.remove();
}
catch (NamingException ex) {
System.err.println(ex);
}
catch (ClassCastException ex) {
System.err.println(ex);
}
catch (CreateException ex) {
System.err.println(ex);
}
catch (RemoteException ex) {
System.err.println(ex);
}
catch (RemoveException ex) {
System.err.println(ex);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -