当前页面: 开发资料首页 → J2EE 专题 → RMI错误,错误错误错误
RMI错误,错误错误错误
摘要: RMI错误,错误错误错误
-------远程接口
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface Rmi1 extends Remote{
String getString()throws RemoteException;
}
-------远程对象
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.rmi.RMISecurityManager;
import javax.naming.*;
import java.rmi.Naming;
import java.rmi.registry.*;
import java.net.*;
public class Rmi1Impl extends UnicastRemoteObject implements Rmi1{
public Rmi1Impl()throws RemoteException{
super();
}
public String getString()throws RemoteException{
String str="不管以后将如何结束只要我们曾经拥有过";
String target="";
for (int i = 0; i<4; i++){
target=target+str.charAt((int)(Math.random()*str.length()));
}
return target;
}
}
---------RMI服务器
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.rmi.RMISecurityManager;
import javax.naming.*;
import java.rmi.Naming;
import java.rmi.registry.*;
import java.net.*;
public class Rmi1Server{
public static void main(String[] args){
System.setSecurityManager(new RMISecurityManager());
try {
Rmi1 rm=new Rmi1Impl();
Naming.rebind("rmi:///localhost",rm);
System.out.println ("ready to do Time");
}
catch (Exception ex) {
ex.printStackTrace();
}
}
}
----------客户端
import java.rmi.*;
import java.rmi.registry.*;
import java.net.*;
public class Display{
Display(){
super();
}
public static void main(String[] args){
System.setSecurityManager(new RMISecurityManager());
try {
Rmi1Impl t=(Rmi1Impl)Naming.lookup("rmi://localhost:6666/rmi1");
for (int i = 0; i<6; i++){
System.out.println ("rmilImpl: "+t.getString());
}
}
catch (Exception ex) {
ex.printStackTrace();
}
}
}
-----为什么最后的错误是我:::
import java.rmi.*;
import java.rmi.registry.*;
import java.net.*;
public class Display{
Display(){
super();
}
public static void main(String[] args){
System.setSecurityManager(new RMISecurityManager());
try {
Rmi1Impl t=(Rmi1Impl)Naming.lookup("rmi://localhost:6666/rmi1");
for (int i = 0; i<6; i++){
System.out.println ("rmilImpl: "+t.getString());
}
}
catch (Exception ex) {
ex.printStackTrace();
}
}
}
高手快过来呀,
-----为什么最后的错误是我:::
java.security.AccessControlException: access denied (java.net.SocketPermission 1
27.0.0.1:1099 connect,resolve)
at java.security.AccessControlContext.checkPermission(AccessControlConte
xt.java:264)
at java.security.AccessController.checkPermission(AccessController.java:
427)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
at java.lang.SecurityManager.checkConnect(SecurityManager.java:1034)
at java.net.Socket.connect(Socket.java:501)
at java.net.Socket.connect(Socket.java:457)
at java.net.Socket.
(Socket.java:365)
at java.net.Socket.(Socket.java:178)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirect
SocketFactory.java:22)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMaster
SocketFactory.java:128)
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:569)
at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:185
)
at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:171)
at sun.rmi.server.UnicastRef.newCall(UnicastRef.java:306)
at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source)
at java.rmi.Naming.rebind(Naming.java:160)
at Rmi1Server.main(Rmi1Server.java:15)
Press any key to continue...
问题,已解决,
本人参考了以下的blog,衷心感谢这个些热心的人.
如有人和我的问题差不多,请访问这些好心人的blog.
http://www.blogcn.com/user82/unmi/blog/36327904.html
过来,说句话,给分了,
呵呵
楼上的楼上在广告!
免费给别人做广告,为他人.也是为自己.
你们不来,我无法给分给别人啊.