访问被拒绝java.net.socket.permission

时间:2013-10-21 19:10:56

标签: java eclipse ftp applet

我是Java的新手,我在Eclipse中创建了一个通过FTP下载文件的applet。当我在Eclipse中运行它时没关系,但是当我从Chrome或IE调用它时出现此错误:

(access denied java.net.socket.permission)

我已将myapplet.classFTPClient.class包含在同一个jar文件中。我也签了jar文件。

HTML电话:

code=applet_test.myapplet archive=ftp.jar 

爪哇:

package applet_test;

import java.applet.Applet;

import java.io.FileNotFoundException;

import java.io.FileOutputStream;

import java.io.IOException;

import java.io.OutputStream;

import java.net.SocketException;

import java.security.AccessController;

import java.security.PrivilegedAction;

import org.apache.commons.net.ftp.FTPClient;


public class myapplet extends Applet 
{

    public static void main(String[] args)
    {}

public void init()
    {

        AccessController.doPrivileged(new PrivilegedAction<Void>() {

public Void run() {
                 // privileged code goes here, for example:


                            String user="petrica";

                    String pass="eekels";

                    String remote="test1.txt";

                    final FTPClient ftp;``
                    ftp = new FTPClient();
                    try {
                        ftp.connect("ftp.eekels.ro");
                    } catch (SocketException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    try {
                        ftp.login(user,pass);
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    if (ftp.isConnected()){
                    System.out.println("conectat");
                    OutputStream iesire = null;
                    try {
                        iesire= new FileOutputStream("c:\\test1.txt");
                    } catch (FileNotFoundException e1) {
                        // TODO Auto-generated catch block
                        e1.printStackTrace();
                    }
                    try {
                        ftp.retrieveFile(remote, iesire);
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }   
                }                
                 return null; // nothing to return
             }
         });
}
}

0 个答案:

没有答案