简体   繁体   English

Java Applet无法使用HTML

[英]Java Applet not Working With HTML

I made an Applet. 我做了一个小程序。 This applet works in appletviewer perfectly. 这个applet在appletviewer中完美地工作。 But, when I put this applet's class file in a directory along with it's Jar File in which I have signed myself, and create an .HTML File with the applet tags it doesn't work. 但是,当我将此applet的类文件与我自己签名的Jar文件一起放在目录中,并使用applet标签创建一个.HTML File时,该文件不起作用。 I keep getting java.security.AccessControlException: access denied . 我一直在获取java.security.AccessControlException: access denied How can I make this work? 我该如何进行这项工作? here is the source code, below it is the problem, and below that is how the applet is embedded.: 这是源代码,下面是问题,下面是小程序的嵌入方式:

import javax.swing.*;
import java.applet.Applet;
import java.applet.AppletContext;
import java.applet.AppletStub;
import java.awt.*;
import java.io.*;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.HashMap;

public class RSLoad extends JApplet implements AppletStub {

/**
 * 
 */
private static final long serialVersionUID = 1L;
private static final HashMap<String, String> PARAMETERS = new HashMap<String, String>();
private static final String LINK = "http://world2.runescape.com/";

public void init() {
    try {
        setVisible(true);
        setSize(775, 540);
        parse(LINK);
        dwnld(LINK + PARAMETERS.get("archive"));
        ClassLoader loader = new URLClassLoader(new URL[]{new File("Runescape.jar").toURI().toURL()});
        Class<?> client = loader.loadClass("Rs2Applet");
        Applet applet = (Applet) client.newInstance();
        applet.setStub(this);
        applet.init();
        applet.start();
        add(applet, BorderLayout.CENTER);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

public void appletResize(int width, int height) {
}

public final String getParameter(String name) {
    return PARAMETERS.get(name);
}
public final URL getDocumentBase() {
    try {
        return new URL(LINK);
    } catch (MalformedURLException e) {
        return null;
    }
}

public final URL getCodeBase() {
    try {
        return new URL(LINK);
    } catch (MalformedURLException e) {
        return null;
    }
}

public final AppletContext getAppletContext() {
    return null;
}

private void parse(final String url) {
    try {
        BufferedReader in = new BufferedReader(new InputStreamReader(new URL(url).openStream()));
        String line;
        while ((line = in.readLine()) != null) {
            if (line.contains("app") && line.contains("write")) {
                PARAMETERS.put("<app", "");
                PARAMETERS.put("let ", "");
            } else if (line.contains("scriptsrc") || line.contains("ie6")) {
            } else if (line.contains("document.write")) {
                line = line.replaceAll("document.write", "").replaceAll("<param name=\"", "").replaceAll("\">'", "\"").replaceAll("'", "").replaceAll("\\(", "").replaceAll("\\)", "").replaceAll("\"", "").replaceAll(" ", "").replaceAll(";", "").replaceAll("value", "");
                String[] splitted = line.split("=");
                if (splitted.length == 1) {
                    PARAMETERS.put(splitted[0], "");
                } else if (splitted.length == 2) {
                    PARAMETERS.put(splitted[0], splitted[1]);
                } else if (splitted.length == 3) {
                    PARAMETERS.put(splitted[0], splitted[1] + splitted[2]);
                }
            }
        }
        in.close();
    } catch (Exception e) {
        System.out.println("Error Parsing!");
    }
}

private void dwnld(final String url) {
    try {
        BufferedInputStream in = new BufferedInputStream(new URL(url).openStream());
        FileOutputStream fos = new FileOutputStream("Runescape.jar");
        BufferedOutputStream out = new BufferedOutputStream(fos, 1024);
        byte[] data = new byte[1024];
        int x;
        while ((x = in.read(data, 0, 1024)) >= 0) {
            out.write(data, 0, x);
        }
        in.close();
        out.close();
    } catch (Exception e) {
        System.out.println("Error Downloading!");
        e.printStackTrace();
    }
}

}` }`

'java.security.AccessControlException: access denied (java.net.SocketPermission world2.runescape.com:80 connect,resolve)
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:374)
at java.security.AccessController.checkPermission(AccessController.java:546)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
at java.lang.SecurityManager.checkConnect(SecurityManager.java:1034)
at sun.plugin2.applet.Applet2SecurityManager.checkConnect(Applet2SecurityManager.java:505)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:528)
at sun.net.www.http.HttpClient.<init>(HttpClient.java:234)
at sun.net.www.http.HttpClient.New(HttpClient.java:307)
at sun.net.www.http.HttpClient.New(HttpClient.java:324)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:970)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:911)
at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:836)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1172)
at java.net.URL.openStream(URL.java:1010)
at RSLoad.dwnld(RSLoad.java:95)
at RSLoad.init(RSLoad.java:26)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Plugin2Manager.java:1639)
at java.lang.Thread.run(Thread.java:680)
java.security.AccessControlException: access denied (java.util.PropertyPermission user.dir read)
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:374)
at java.security.AccessController.checkPermission(AccessController.java:546)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
at java.lang.SecurityManager.checkPropertyAccess(SecurityManager.java:1285)
at java.lang.System.getProperty(System.java:667)
at java.io.UnixFileSystem.resolve(UnixFileSystem.java:118)
at java.io.File.getAbsolutePath(File.java:501)
at java.io.File.getAbsoluteFile(File.java:517)
at java.io.File.toURI(File.java:660)
at RSLoad.init(RSLoad.java:27)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Plugin2Manager.java:1639)
at java.lang.Thread.run(Thread.java:680)

Embedded like this: 像这样嵌入:

 <html>
 <body>
 <applet code=RSLoad.class archive="RSLoad.jar" width=100% height=100%>
 </applet>
 </body>
 </html>

Either your certificate is not trusted in the browser, or the user hasn't given explicit permission. 您的证书在浏览器中不受信任,或者用户未获得显式权限。 You've given us the code (definately a good thing), but nothing about the signature itself, the browser or the way you've embedded the applet. 您已经给我们提供了代码(绝对是一件好事),但是与签名本身,浏览器或嵌入applet的方式无关。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM