jnorthr
jnorthr

Reputation: 62

can groovy script respond to ajax client request

I have jquery code in a web browser for an autocomplete box to send an ajax request to my server. I cannot figure out how to code my server groovy script to reply back to the browser. should it look like a servlet with request/response variables or is there another way ?

Upvotes: 0

Views: 675

Answers (1)

Flamboyaa
Flamboyaa

Reputation: 36

I would suggest to use the groovlet that is included in the groovy-all library. Then you can use it like this in your web.xml:

<servlet>
    <servlet-name>Groovy</servlet-name>
    <servlet-class>groovy.servlet.GroovyServlet</servlet-class>
</servlet>

<servlet-mapping>
    <servlet-name>Groovy</servlet-name>
    <url-pattern>*.groovy</url-pattern>
</servlet-mapping>

With this you can send your data to your groovy script and write out with the print methods to get your response back. Groovlets has implicit objects for the request, response, session etc that can be used directly in the script.

Hope it helps.

Upvotes: 1

Related Questions