beanshelljavascript解释器

3b6akqbq  于 2021-07-12  发布在  Java
关注(0)|答案(0)|浏览(300)

我正在尝试用beanshell运行以下javascript代码:

Interpreter engine = new Interpreter();
    String JScode = "var object = {\n" +
            "  id : \"house\",\n" +
            "  value : 20,\n" +
            "  date : new Date(),\n" +
            "  Log : function(){\n" +
            "    return this.date.getDay() +'/'+ this.date.getMonth();\n" +
            "  }\n" +
            "}";
    try {
        engine.eval(JScode);
        engine.eval("var test = object.Log()");
        String test = engine.get("test").toString();
        System.out.println(test);
    } catch (EvalError evalError) {
        evalError.printStackTrace();
    }

但我有个错误:

Parse error at line 2, column 6.  Encountered: :
at bsh.Parser.generateParseException(Unknown Source)
at bsh.Parser.jj_consume_token(Unknown Source)
at bsh.Parser.ArrayInitializer(Unknown Source)
at bsh.Parser.VariableInitializer(Unknown Source)
at bsh.Parser.VariableDeclarator(Unknown Source)
at bsh.Parser.TypedVariableDeclaration(Unknown Source)
at bsh.Parser.BlockStatement(Unknown Source)
at bsh.Parser.Line(Unknown Source)
at bsh.Interpreter.Line(Unknown Source)
at bsh.Interpreter.eval(Unknown Source)
at bsh.Interpreter.eval(Unknown Source)
at bsh.Interpreter.eval(Unknown Source)
at jsEngineTester.BeanShellEngine.main(BeanShellEngine.java:139)

在beanshell上执行js脚本需要做什么?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题