register
other register

Tuesday, July 29, 2008

Groovlets

For more details please refer to: Groovlets


1. Put the following lines into web.xml in WEB-INF foler

=====================================

<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>

=====================================


2. Write your Groovlets hello.groovy like below, and put it into the webapps folder

=====================================

import java.util.Date
import groovy.xml.MarkupBuilder

if (session == null) {
session = request.getSession(true);
}

if (session.counter == null) {
session.counter = 1
}

html.html { // html is implicitly bound to new MarkupBuilder(out)
head {
title("Groovy Servlet")
}
body {
p("Hello, ${request.remoteHost}: ${session.counter}! ${new Date()}")
}
}

session.counter = session.counter + 1

====================================

3. Copy groovy-all-xyz.jar into WEB-INF/lib folder


Notes:

If your Groovlets is at somewhere else rather than $CATALINA_HOME/webapps, then you need to edit the server.xml in the $CATALINA_HOME/conf like below:

<Context path="/groovy" docBase="c:/groovy-servlet"/>

No comments: