helloclient.java

来自「学习EJB的很好范例」· Java 代码 · 共 48 行

JAVA
48
字号
package com.wiley.compBooks.roman.session.helloworld;

import javax.ejb.*;
import javax.naming.*;
import java.rmi.*;
import java.util.Properties;

/**
 * This class is an example of client code which invokes
 * methods on a simple stateless session bean.
 */
public class HelloClient {

	public static void main(String[] args) {

		try {
			/*
			 * Get System properties for JNDI initialization
			 */
			Properties props = System.getProperties();

			/*
			 * Get a reference to the HelloHome Object - the
			 * factory for Hello EJB Objects
			 */
			Context ctx = new InitialContext(props);
			HelloHome home = (HelloHome) ctx.lookup("HelloHome");

			/*
			 * Use the factory to create the Hello EJB Object
			 */
			Hello hello = home.create();

			/*
			 * Call the hello() method, and print it
			 */
			System.out.println(hello.hello());

			/*
			 * Done with EJB Object, so remove it
			 */
			hello.remove();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

⌨️ 快捷键说明

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