rhino

httpclient + javascript

喜夏-厌秋 提交于 2020-01-16 20:55:29
问题 I am using Apache Httpclient and I need to use a Javascript engine to run the script for the page. Similar to a small web browser. Does anybody know a way to integrate javascript with httpclient and send a request back to the original server? 回答1: Checkout http://htmlunit.sourceforge.net/ 来源: https://stackoverflow.com/questions/5587389/httpclient-javascript

Rhino JS / ScriptEngine from Java - integers in, doubles out?

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-14 14:30:11
问题 I'm trying out Rhino to embed Javascript in Java. I noticed that when I eval a script that adds two ints together in Javascript, the result comes back as a Double. ScriptEngine engine = new ScriptEngineManager().getEngineByName("JavaScript"); engine.put("x", 3); engine.put("y", 4); assertEquals(3, engine.eval("x")); // OK assertEquals(4, engine.eval("y")); // OK assertEquals(7, engine.eval("x + y")); // FAILS, actual = (Double) 7.0 So why does the x + y expression return a double instead of

Accessing java Maps & Lists as JavaScript Objects in Rhino

旧街凉风 提交于 2020-01-12 22:11:10
问题 Is there a way to access Java Maps and Lists as JavaScript Objects in Rhino? I have a Map which contains only other maps and lists of primitives and Strings, I'd like to pass this to a Rhino script and do stuff to it, and return the modified object back out to Java - but since they are java.util.Map and java.util.List Objects, I can't use standard JavaScript associative array syntax. ie: fooMap.get("keyName") will work, but fooMap.keyName and fooMap["keyName"] will not. I don't know if there

Accessing java Maps & Lists as JavaScript Objects in Rhino

我怕爱的太早我们不能终老 提交于 2020-01-12 22:09:03
问题 Is there a way to access Java Maps and Lists as JavaScript Objects in Rhino? I have a Map which contains only other maps and lists of primitives and Strings, I'd like to pass this to a Rhino script and do stuff to it, and return the modified object back out to Java - but since they are java.util.Map and java.util.List Objects, I can't use standard JavaScript associative array syntax. ie: fooMap.get("keyName") will work, but fooMap.keyName and fooMap["keyName"] will not. I don't know if there

Java ScriptEngine (nashorn & rhino) : how to stack scopes / bindings?

放肆的年华 提交于 2020-01-04 17:54:47
问题 I have to port a software using Rhino1.7R4 and its org.mozilla.javascript package to use the javax.script package and its ScriptEngine ( Rhino in Java 6 & 7, Nashorn in Java 8). The main problem is to stack scopes (Bindings). Using the Rhino jar, I do: Scriptable scope ... Scriptable newScope = javascriptContext.initStandardObjects(); newScope.setParentScope(scope); So if a variable is defined without var, it's a global variable (root scope) if a variable is defined with var, it's a local

Error trying to access class members (using Rhino)

99封情书 提交于 2020-01-03 02:40:06
问题 Trying to create a Java/JS link using Rhino with two very simple objects, one having as one member an instance of the second class. Running the code below gives the following error: org.mozilla.javascript.EcmaError: TypeError: Cannot find default value for object. The problem seems to be accessing the member "a" from within second object. I've also tried with a getter like this: public Object jsGet_a() { return Context.toObject(a, this); } but i get the same error. new A().doSmth(); is

No Array.filter() in Rhino?

旧城冷巷雨未停 提交于 2020-01-02 07:24:25
问题 Why can't I use Array.filter() in Rhino? The code is like this: var simple_reason = ["a", "b", "c"]; print(typeof simple_reason.filter); var not_so_simple_reason = new Array("a", "b", "c"); print(typeof not_so_simple_reason.filter); Both cases output "undefined". 回答1: There is no standardized filter function for Javascript Arrays, it is only an extension to the standard. (There is as of the ES5 spec published just a month after this answer was posted.) The MDC reference page gives you an

Rhino: How to get all properties from ScriptableObject?

心已入冬 提交于 2020-01-02 04:47:07
问题 I am using a Javascript object as an object with configuration properties. E.g. I have this object in javascript: var myProps = {prop1: 'prop1', prop2: 'prop2', 'prop3': 'prop3'}; This object (NativeObject) is returned to me in Java function. E.g. public Static void jsStaticFunction_test(NativeObject obj) { //work with object here } I want to get all properties from object and build HashMap from it. Any help will be appreciated. 回答1: well, if you looked closer, you would have seen that

Stopping the Rhino Engine in middle of execution

左心房为你撑大大i 提交于 2020-01-02 04:31:09
问题 Does the Rhino engine have an api that can stop the execution of a script fie in the middle. For example, I have a script file in which there is an infinte loop. How can I stop the execution in the middle? Of course, I can stop the jvm which started the Rhino engine to excecute the script. But I don't want to kill the entire jvm session for that reason as i have started the script programatically and the Rhino Engine also running in the same JVM as my application. 回答1: Stopping the execution

Is it possible to make Node.js use Rhino as the Javascript engine?

两盒软妹~` 提交于 2020-01-01 04:11:11
问题 I use Node.js for several jobs on my web apps and so far everthing's ok. But the Node.js uses Google's V8 as the default Javascript engine (JSE) and V8 runs exlusively on the x86 and ARM Instruction Set Architectures (ISA). Now I have a PPC processor Mac computer on which I want to run the Node.js . To do that, I'm adviced to use the Rhino + OpenJDK Shark Virtual Machine + Low Level Virtual Machine (LLVM) as the JIT compiler. Currently, that looks like the most applicable way of running Node