R – Groovlet in Grails apps

grailsgroovy

How do I drop a Groovlet into a Grails app? Say, for example, in web-app/groovlet.groovy

import java.util.Date

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

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

println """
<html>
    <head>
        <title>Groovy Servlet</title>
    </head>
    <body>
Hello, ${request.remoteHost}: Counter: ${session.counter}! Date: ${new Date()}
<br>
"""

Best Answer

  1. grails install-templates
  2. Edit src/templates/web/web.xml to include your groovlet
  3. grails war
  4. deploy

I've not personally done this to incorporate a groovlet, but this is the documented way to modify the deployed Grails web.xml

Related Topic