给你一个例子吧import java.io.*;
import java.rmi.*;
import java.rmi.server.*;
import sun.applet.*;
import java.rmi.registry.LocateRegistry;/**
* Title:
* Description:
* Copyright: Copyright (c) 2002
* Company:
* @author
* @version 1.0
*/public class RmiHelloServer
{ public RmiHelloServer()
{
}
public static void main(String[] args)
{
//创建并安装安全管理器
if(System.getSecurityManager()==null)
{
System.setSecurityManager(new RMISecurityManager());
} try{
//创建远程对象
RmiHelloRemoteObj ttt=new RmiHelloRemoteObj();
//启动注册表
LocateRegistry.createRegistry(2222);
//奖名称绑定到对象
Naming.rebind("//Fangm:2222/helloObj",ttt); System.out.println("RMI服务器正在运行");
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
import java.rmi.server.*;
import java.rmi.*;/**
* Title:
* Description:
* Copyright: Copyright (c) 2002
* Company:
* @author
* @version 1.0
*/public class RmiHelloRemoteObj extends UnicastRemoteObject implements RmiHelloRemoteIntfc
{ public RmiHelloRemoteObj() throws RemoteException
{
super();
} public String helloRemoteObj(String client) throws RemoteException
{
return "Hello World"+client;
}
import java.rmi.*;/**
* Title:
* Description:
* Copyright: Copyright (c) 2002
* Company:
* @author
* @version 1.0
*/public interface RmiHelloRemoteIntfc extends Remote
{
String helloRemoteObj(String client) throws RemoteException;
}import java.rmi.*;
import java.rmi.server.*;/**
* Title:
* Description:
* Copyright: Copyright (c) 2002
* Company:
* @author
* @version 1.0
*/public class RmiHelloClient
{ public RmiHelloClient()
{
}
public static void main(String[] args)
{
//创建并安装安全管理器
if(System.getSecurityManager()==null)
{
System.setSecurityManager(new RMISecurityManager());
} try{
RmiHelloRemoteIntfc c1=(RmiHelloRemoteIntfc)Naming.lookup("rmi://Fangm:2222/helloObj");
System.out.println(c1.helloRemoteObj("Everyone"));
}
catch(Exception e)
{
e.printStackTrace();
}
System.exit(0); }
}
import java.rmi.*;
import java.rmi.server.*;
import sun.applet.*;
import java.rmi.registry.LocateRegistry;/**
* Title:
* Description:
* Copyright: Copyright (c) 2002
* Company:
* @author
* @version 1.0
*/public class RmiHelloServer
{ public RmiHelloServer()
{
}
public static void main(String[] args)
{
//创建并安装安全管理器
if(System.getSecurityManager()==null)
{
System.setSecurityManager(new RMISecurityManager());
} try{
//创建远程对象
RmiHelloRemoteObj ttt=new RmiHelloRemoteObj();
//启动注册表
LocateRegistry.createRegistry(2222);
//奖名称绑定到对象
Naming.rebind("//Fangm:2222/helloObj",ttt); System.out.println("RMI服务器正在运行");
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
import java.rmi.server.*;
import java.rmi.*;/**
* Title:
* Description:
* Copyright: Copyright (c) 2002
* Company:
* @author
* @version 1.0
*/public class RmiHelloRemoteObj extends UnicastRemoteObject implements RmiHelloRemoteIntfc
{ public RmiHelloRemoteObj() throws RemoteException
{
super();
} public String helloRemoteObj(String client) throws RemoteException
{
return "Hello World"+client;
}
import java.rmi.*;/**
* Title:
* Description:
* Copyright: Copyright (c) 2002
* Company:
* @author
* @version 1.0
*/public interface RmiHelloRemoteIntfc extends Remote
{
String helloRemoteObj(String client) throws RemoteException;
}import java.rmi.*;
import java.rmi.server.*;/**
* Title:
* Description:
* Copyright: Copyright (c) 2002
* Company:
* @author
* @version 1.0
*/public class RmiHelloClient
{ public RmiHelloClient()
{
}
public static void main(String[] args)
{
//创建并安装安全管理器
if(System.getSecurityManager()==null)
{
System.setSecurityManager(new RMISecurityManager());
} try{
RmiHelloRemoteIntfc c1=(RmiHelloRemoteIntfc)Naming.lookup("rmi://Fangm:2222/helloObj");
System.out.println(c1.helloRemoteObj("Everyone"));
}
catch(Exception e)
{
e.printStackTrace();
}
System.exit(0); }
}
解决方案 »
- 急急急 在线等 hibernate查询对象的问题
- 谁用过 facebook 的 scribe 做过日志系统 ? 用 java 能写客户端么
- digester报错,求解决,在线等!!
- 怎么保持SSH分页状态?
- 求webservice资料
- spring在使用定时作业调度quartz的问题
- 【我在webapps下面放了一个一般的文件夹(里面不含jsp,html),我应该怎么访问这个文件啊?】
- java中的Stirng类型映射到mysql中的text类型出现错误。
- 有谁想过这个问题吗?
- mysql驱动程序问题(安装配置jive时碰到的):能否同时存在多个驱动程序呢,端口冲突了?
- 在查找ejb时有没有什么方式让查找的速度快一些,我在程序启动时连接ejb,速度奇曼,又没有什么更好的方案呢?
- 我有个关于XML的初级问题。
Calculator c;//Calculator 为远程借口
c= (Calculator) Naming.lookup("//localhost/CalculatorService");//**
怎么会有类型不匹配呢?如果是类型不匹配的话,编译应该都不会过去的,是吧!?
c= (Calculator) Naming.lookup("//localhost/CalculatorService");
上,帮忙给看看呀!
看了很多资料都没有涉及这个问题,真得跳楼了?!
jndi为://localhost/CalculatorService
的对象是否正确
我根本就没有用JNDI啊.
c= (Calculator) Naming.lookup("//localhost/CalculatorService");//**
对比一下啊。看看有什么不同呢?