从JavaScript调用Applet URLConnection.connect后失败

从JavaScript调用Applet URLConnection.connect后失败,java,javascript,security,applet,Java,Javascript,Security,Applet,我有一个带有Java小程序的网站,这个小程序需要连接到我的服务器。 这在JApplets@Override init()中有效,但在javascript调用的我自己的函数中无效 final URL url = new URL(SERVER_URL + action); System.out.println("url:" + url); System.out.println("postString: " + postString); final HttpURLConnection connecti

我有一个带有Java小程序的网站,这个小程序需要连接到我的服务器。 这在JApplets@Override init()中有效,但在javascript调用的我自己的函数中无效

final URL url = new URL(SERVER_URL + action);
System.out.println("url:" + url);
System.out.println("postString: " + postString);
final HttpURLConnection connection = (HttpURLConnection) url.openConnection();
if(!postString.isEmpty()) {
    connection.setRequestMethod("POST");
    connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
    connection.setRequestProperty("Content-Length", Integer.toString(postString.getBytes().length));
    connection.setUseCaches(false);
    connection.setDoInput(true);
    connection.setDoOutput(true);

    System.out.println("connecting...");
    connection.connect(); // same with connection.getOutputStream();
    System.out.println("connected");
    ....
网站:

<a href="javascript: document.applet.update();" title="update from server">Update</a>
<applet id="applet" archive="/public/Antucation-0.1.0.jar?random=3765332307555812156" code="de.antucation.controller.Controller.class" width="100%" height="800px">
<param name="colonyId" value="1">
</applet>
我试着用一个System.out呼叫来解决这个问题,但也没有发生任何事情。 然而,这绝对是好的:

@Override
public void init() {
    update();
}
哦,小程序当然也来自
http://localhost:9000/


如何解决或修复此问题?

尝试以下方法:

public void callFromJavaScript(final String param) {
    AccessController.doPrivileged( new PrivilegedAction<Void>() {
        public Void run() {
            // call code to make the connection..
            return null;
        }
    });
}
public void callFromJavaScript(最终字符串参数){
AccessController.doPrivileged(新的PrivilegedAction(){
公开募捐{
//调用代码以建立连接。。
返回null;
}
});
}

如何从javascript中调用它?您好,stackoverflow在我提交文章时丢失了90%的内容,几秒钟后我就可以编辑并修复它了。现在一切都在那里:)非常感谢你,我已经花了大约10个小时了!请注意:public void callFromJavaScript(){AccessController.doPrivileged(新的PrivilegedAction(){@Override public void run(){update();return null;}}});}哦,是的,这是从我今天早些时候在JS/applet交互中看到的一个相同问题匆忙复制而来的。很高兴你把它整理好了。
public void callFromJavaScript(final String param) {
    AccessController.doPrivileged( new PrivilegedAction<Void>() {
        public Void run() {
            // call code to make the connection..
            return null;
        }
    });
}