Developer - Groovy Server Pages

Groovy Server Pages

The GSP implementation in Grails was forked from the original GSP, but has been heavily refactored and is now based around the TemplateEngine pattern found in the rest of Groovy. The core classes for GSP can be found in the org.codehaus.groovy.grails.web.pages package.

There is a servlet that maps to *.gsp that handles all GSP request called GroovyPagesServlet. This class uses the GroovyPagesTemplateEngine class to process a GSP request.

As mentioned the API for the GroovyPagesTemplateEngine is very similar to the other TemplateEngine's in Groovy, making GSP into a re-usable component. General API usage is as follows:

groovy.text.Template t = engine.createTemplate(context,request,response);
        if(t != null) {
           groovy.lang.Writable w = t.make();
           Writer out = ..// get writer from somewhere
           w.writeTo(out);
        }

Thanks to the refactoring into a TemplateEngine the GroovyPagesTemplateEngine is re-used in several places including in the GSP servlet, in tags libraries and in the render method of controllers.

The Parse, Reverse, Scan, Strip and Tokens classes in the org.codehaus.groovy.grails.web.pages are used to convert a GSP into a Groovy class that extends the GroovyPage class which in turn extends groovy.lang.Script.

Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.