A generic servlet for serving (mostly HTML) templates.
It delegates work to a groovy.text.TemplateEngine implementation
processing HTTP requests.
Usage
helloworld.html is a headless HTML-like template
<html>
<body>
<% 3.times { %>
Hello World!
<% } %>
<br>
</body>
</html>
Minimal web.xml example serving HTML-like templates
<web-app>
<servlet>
<servlet-name>template</servlet-name>
<servlet-class>groovy.servlet.TemplateServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>template</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
</web-app>
Template engine configuration
By default, the TemplateServer uses the
groovy.text.SimpleTemplateEngine which interprets JSP-like templates. The init parameter template.engine
defines the fully qualified class name of the template to use:
template.engine = [empty] - equals groovy.text.SimpleTemplateEngine
template.engine = groovy.text.SimpleTemplateEngine
template.engine = groovy.text.GStringTemplateEngine
template.engine = groovy.text.XmlTemplateEngine
Logging and extra-output options
This implementation provides a verbosity flag switching log statements.
The servlet init parameter name is:
generate.by = true(default) | false
See Also: TemplateServlet.setVariables(ServletBinding) author: Christian Stein author: Guillaume Laforge version: 2.0 |