Groovlet in Grails Applications

How to fall Groovlet in 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>
"" "

+3
source share
2 answers
  • grails install-templates
  • Edit src/templates/web/web.xmlto enable your groovlet
  • grails war
  • expand

I personally did not do this to enable groovlet, but this is a documented way to change the deployed Grails web.xml

+6
source

, groovlets , Servlet Groovy scripting,

, Grails - controller HTML GSP.

- ( , ):

Grails-//SampleController.groovy

class DateController {
    def index = {
        if (session == null) {
          session = request.getSession(true);
        }

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

-//index.gsp

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

, !

0

Source: https://habr.com/ru/post/1698782/


All Articles