helloimpl.java

来自「写给JSP初级程序员的书」· Java 代码 · 共 45 行

JAVA
45
字号
package jdeveloper.rmi_iiop;import javax.naming.*;import java.rmi.RemoteException;import java.rmi.RMISecurityManager;//import java.rmi.server.UnicastRemoteObject;import javax.rmi.PortableRemoteObject;public class HelloImpl extends PortableRemoteObject    implements Hello {    public HelloImpl() throws RemoteException {        super();    }    public String sayHello() {        return  "Hello World!";    }    public static void main(String args[]) {         // Create and install a security manager         if (System.getSecurityManager() == null) { 	    System.setSecurityManager(new RMISecurityManager());         }         try { 	    Hello obj = new HelloImpl(); 	    // Bind this object instance to the name "HelloServer" 	    	    //***** old code for rmi	    // Naming.rebind("HelloServer", obj); 	    	    //***** new code for rmi-iiop	    	    	    Context initialNamingContext = new InitialContext();	    	    initialNamingContext.rebind("HelloServer", obj); 	    	    System.out.println("HelloServer bound in registry");         } catch (Exception e) { 	    System.out.println("HelloImpl err: " + e.getMessage()); 	    e.printStackTrace();         }     } }

⌨️ 快捷键说明

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