keren
12-07-2005, 07:22 AM
Hello,everyone, I just got a problem,I want to execute a script in my <method> or <script>, just like beanshell or javascript eval(),but I don't know how to do it?
for exmple,in javascript:
-----------------------
<script language="javascript">
function doRun(){
alert("before changed "+document.forms[0].user.value);
var val;
eval("val=document.forms[0].user.value");
alert("1 after changed"+val);
eval("val=(document.forms[0].user.value='asch')");
alert("2 after changed"+val);
alert(document.forms[0].user.value);
}
</script>
---------------------
and in beanshell:
---------------------
package org.beanshell;
import java.io.*;
import bsh.Interpreter;
public class TestBSH {
public TestBSH() {}
public static void main(String[] args) {
TestBSH testBSH1 = new TestBSH();
testBSH1.go();
testBSH1.go1();
System.exit( -1);
}
void go() {
try {
//eval
Interpreter bsh = new Interpreter();
bsh.eval("for(int i=0;i<10;i++){System.out.println(i);}");
java.util.Date d = new java.util.Date();
bsh.set("date", d);
System.out.println("=" + bsh.get("date").toString());
} catch (Exception ex) {
ex.printStackTrace();
}
}
void go1() {
try {
//String str = (String)new Interpreter().source("mystr.bsh");
//System.out.println("=="+str);
Object sum = new Interpreter().source("myadd.bsh");
System.out.println("sum=" + sum);
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
/**
--the following is myadd.bsh file' contents:
int add(int a,int b){
return a+b;
}
return add(8,8);
*/
---------------------
thanks.
for exmple,in javascript:
-----------------------
<script language="javascript">
function doRun(){
alert("before changed "+document.forms[0].user.value);
var val;
eval("val=document.forms[0].user.value");
alert("1 after changed"+val);
eval("val=(document.forms[0].user.value='asch')");
alert("2 after changed"+val);
alert(document.forms[0].user.value);
}
</script>
---------------------
and in beanshell:
---------------------
package org.beanshell;
import java.io.*;
import bsh.Interpreter;
public class TestBSH {
public TestBSH() {}
public static void main(String[] args) {
TestBSH testBSH1 = new TestBSH();
testBSH1.go();
testBSH1.go1();
System.exit( -1);
}
void go() {
try {
//eval
Interpreter bsh = new Interpreter();
bsh.eval("for(int i=0;i<10;i++){System.out.println(i);}");
java.util.Date d = new java.util.Date();
bsh.set("date", d);
System.out.println("=" + bsh.get("date").toString());
} catch (Exception ex) {
ex.printStackTrace();
}
}
void go1() {
try {
//String str = (String)new Interpreter().source("mystr.bsh");
//System.out.println("=="+str);
Object sum = new Interpreter().source("myadd.bsh");
System.out.println("sum=" + sum);
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
/**
--the following is myadd.bsh file' contents:
int add(int a,int b){
return a+b;
}
return add(8,8);
*/
---------------------
thanks.