蓝森林首页 | 返回主页 | 本站地图 | 站内搜索 | 联系信箱 |
 您目前的位置:首页 > 自由软件 > 技术交流 > 应用编程


    

蓝森林 http://www.lslnet.com 2006年6月6日 10:18


AccessControlException异常,帮忙分析一下原因?

程序源代码如下:

import java.awt.*;
import java.net.*;
import java.io.*;
import java.applet.Applet;

public class ReadServerFile extends Applet{

        URL fileURL;
        TextArea contents;
        InputStream input;
        DataInputStream dataInput;
       
       
        public void init()
        {
                contents=new TextArea("Please wait..",10,40);
                add(contents);
               
                try
                {
                        fileURL=new URL("http://www.deitel.com/test/test.txt");
                }
                catch(MalformedURLException e)
                {
                        showStatus("Exception : "+e.toString());
                }
        }
       
       
       
        public void start()
        {
                String text;
               
                try{
                        input=fileURL.openStream();
                        dataInput=new DataInputStream(input);
                        contents.setText("The file contents are :\n");
                        while((text=dataInput.readLine())!=null)
                                contents.appendText(text+"\n");
                               
                        dataInput.close();
               
                }
               
                catch(IOException e){
                        showStatus("Exception :" +e.toString());
                }
        }
}


运行异常如下:我是通过代理服务器上网的。
java.security.AccessControlException: access denied (java.net.SocketPermission www.deitel.com resolve)

        at java.security.AccessControlContext.checkPermission(AccessControlContext.java:270)

        at java.security.AccessController.checkPermission(AccessController.java:401)

        at java.lang.SecurityManager.checkPermission(SecurityManager.java:542)

        at java.lang.SecurityManager.checkConnect(SecurityManager.java:1042)

        at sun.plugin.net.protocol.http.HttpURLConnection.checkPermission(HttpURLConnection.java:203)

        at sun.plugin.net.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:147)

        at sun.plugin.net.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:375)

        at java.net.URL.openStream(URL.java:960)

        at ReadServerFile.start(ReadServerFile.java:36)

        at sun.applet.AppletPanel.run(AppletPanel.java:371)

        at java.lang.Thread.run(Thread.java:536)

AccessControlException异常,帮忙分析一下原因?

The file doesn't have world-wide readable permission, the file simply does not exist, the path to the file is wrong, or even maybe the web server is down.  Whatever the reason, it is not accessible!

AccessControlException异常,帮忙分析一下原因?

可是,怎么解决呢?

AccessControlException异常,帮忙分析一下原因?

你试试:
写一个文件policy.all内容如下:

grant {
   permission java.security.AllPermission "", "";
};

然后:java -Djava.security.policy=policy.all ReadServerFile
如果未解决问题,检查一下register端口号和你机器的hostname/ip地址  
一般情况下,当你遇到AccessControlException, it will be in the following format:

java.security.AccessControlException: access denied (<type>; <name>; <actions>;)

然后你可以在permission tag写入type, name and actions.

just like this:
<permission type="java.net.SocketPermission" name="www.deitel.com" actions="connect,resolve" />;



Copyright © 1999-2000 LSLNET.COM. All rights reserved. 蓝森林网站 版权所有。 E-mail : webmaster@lslnet.com