?? helloclient.java
字號:
/*
* Copyright 1999 by dreamBean Software,
* All rights reserved.
*/
package masteringrmi.helloejb.client;
import java.rmi.RemoteException;
import javax.ejb.CreateException;
import javax.naming.InitialContext;
import javax.naming.Context;
import javax.naming.NamingException;
import masteringrmi.helloejb.interfaces.HelloHome;
import masteringrmi.helloejb.interfaces.HelloWorld;
/**
* This is an application that will talk to an EJB component.
*
* It will use JNDI to find the component, then the home will be used instantiate it, and finally call it.
*
* @see HelloWorld
* @author Rickard 謆erg (rickard@dreambean.com)
*/
public class HelloClient
{
// Static -------------------------------------------------------
public static void main(String[] args)
throws Exception
{
new HelloClient();
}
// Constructors --------------------------------------------------
public HelloClient()
throws Exception
{
// Find home for HelloEJB
HelloHome home;
try
{
Context ctx = new InitialContext();
home = (HelloHome)javax.rmi.PortableRemoteObject.narrow(ctx.lookup("HelloEJB"), HelloHome.class);
ctx.close();
} catch (NamingException e)
{
System.out.println("Could not lookup HelloEJB home");
throw e;
}
// Create HelloEJB
HelloWorld helloEJB;
try
{
helloEJB = home.create();
} catch (CreateException e)
{
System.out.println("Could not create HelloEJB");
throw e;
}
// Get greeting
String greeting;
try
{
greeting = helloEJB.helloWorld("World");
} catch (RemoteException e)
{
System.out.println("Could not get greeting from HelloEJB");
throw e;
} finally
{
helloEJB.remove();
}
// Print greeting
System.out.println(greeting);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -