callhelloworld.java

来自「java编程最好的书籍,感觉对初学者或者中级java人员帮助很大」· Java 代码 · 共 48 行

JAVA
48
字号
package examples;

import java.security.*;
import javax.naming.*;
import java.util.Hashtable;
import javax.rmi.PortableRemoteObject;

/**
 * This is a helper class that knows how to call a
 * "Hello, World!" bean.  It does so in a secure manner,
 * automatically propagating the logged in security context
 * to the J2EE server.
 */
public class CallHelloWorld implements PrivilegedAction {
 
 /*
  * This is our one business method.  It performs an action
  * securely, and returns application-specific results.
  */
 public Object run() {
  String result = "Error";
  try {
   /*
    * Make a bean
    */
   Context ctx = new InitialContext(System.getProperties());
   Object obj = ctx.lookup("HelloHome");
   HelloHome home = (HelloHome)
    PortableRemoteObject.narrow(obj, HelloHome.class);
   Hello hello = home.create();

   /*
    * Call a business method, propagating the security context
    */
   result = hello.hello();
  }
  catch (Exception e) {
   e.printStackTrace();
  }
  
  /*
   * Return the result to the client
   */
  return result;
 }
}

⌨️ 快捷键说明

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