Last time I tried, though ScriptEngine is whitelisted, it is not available in the production environment. I had to package the Rhino.jar along with my app.
For examples on general usage of scripting in Java, you can refer to the Java documentation itself.
Though, note that in the GAE/J environment you will need to invoke the Rhino APIs directly.
For example,
// Import statements.
import org.mozilla.javascript.Context;
import org.mozilla.javascript.Scriptable;
private Object executeUsingRhino(String script) throws Exception
{
Context ctx = Context.enter();
try
{
Scriptable scope = ctx.initStandardObjects();
return ctx.evaluateString(scope, script, "<cmd>", 1, null);
}
finally
{
Context.exit();
}
}
// Invoke a script that returns a string output using the following code snippet
String output = Context.toString(executeUsingRhino(script));