how to return value from groovy to java

Posted by Sid on Stack Overflow See other posts from Stack Overflow or by Sid
Published on 2011-03-11T00:05:51Z Indexed on 2011/03/11 0:10 UTC
Read the original article Hit count: 157

Filed under:
|

Hi

I am very new to groovy and having trouble with some parts.

I have a jsp page tied to a servlet that runs groovy scripts. I am able to get to the groovy script from the servlet. But after the script runs how do I return the response from the groovy script back to the servlet to be displayed in the jsp page?

My java servlet code is as follows:

File file = new File("TestScript.groovy");      
ClassLoader parent = getClass().getClassLoader();
GroovyClassLoader loader = new GroovyClassLoader(parent);
Class groovyClass = loader.parseClass(file);
Object[] args = {};
GroovyObject groovyObject = (GroovyObject) groovyClass.newInstance();
groovyObject.invokeMethod("runTest", args);

© Stack Overflow or respective owner

Related posts about java

Related posts about groovy