gpt4 book ai didi

javax.script.ScriptException : sun. org.mozilla.javascript.internal.EcmaError:ReferenceError: "document"未定义

转载 作者:太空宇宙 更新时间:2023-11-04 13:56:09 26 4
gpt4 key购买 nike

我运行下面的 java 文件时遇到此错误。

 import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.util.List;

import javax.script.Bindings;
import javax.script.Invocable;
import javax.script.ScriptContext;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;

public class TestForTheThread {
public static void main(String args[]) {
ScriptEngineManager mgr = new ScriptEngineManager();
ScriptEngine engine = mgr.getEngineByName("javascript");
try {
URL yahoo = new URL("http://localhost/XMLLoadProject/thiru.js");
URLConnection yc = yahoo.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream()));
engine.eval(in);
} catch (ScriptException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("fail to load");
}catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("fail to load");
}
Invocable invocable = (Invocable) engine;
Object result;
try {
result = invocable.invokeFunction("idplogurl", "thriu");
System.out.println(result);
} catch (ScriptException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
}
}
}

示例 js 文件

var idplogurl = function(idpcode) {
/*! jQuery v1.11.2 | (c) 2005, 2014 jQuery Foundation, Inc. | jquery.org/license */
document.write('<script type="text/javascript" src="'+ idpcode+ '"></script>');
}

在 javascript 文件('thiru.js')中包含该文档(javascript 默认对象)。有些网站说没有浏览器就不可能。请任何人针对此错误提出质疑。我收到此错误

javax.script.ScriptException:sun.org.mozilla.javascript.internal.EcmaError:ReferenceError:“文档”未定义。 (#17) 在第 17 行

请帮助我......

最佳答案

尝试使用这个或驼色外壳

ScriptEngine engine = mgr.getEngineByName("JavaScript");
or
ScriptEngine engine = mgr.getEngineByName("javaScript");

粘贴您的 JavaScript 代码

尝试this你可能会得到一些想法。

关于javax.script.ScriptException : sun. org.mozilla.javascript.internal.EcmaError:ReferenceError: "document"未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29797019/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com