What is Groovlet?

A Groovlet is a Servlet in Groovy script or in other word Servlets in Groovy

What it does?

The groovlet jar helps us  to automatically compile  .groovy source files into bytecode.
It load the Class and cache it until you change the source file.

What can be done using Groovlet?
Similar to JSP/Servlet in java we can use of implicit variables to access the session, output and request and many other variables

What is MarkupBuilder?
MarkupBuilder(out) binds html
Using the html.html we can output as html

html.html {
head {
title(‘Groovlet’)
}
body {
p(“Yeh, ${request.remoteHost}: ${session.counter}! ${new Date()}”)
}
}

How to Set up groovylets
Add the following to your web.xml:

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

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

Sources Groovy Docs

Leave a Reply