public class GroovyServlet
extends AbstractHttpServlet
This servlet will run Groovy scripts as Groovlets. Groovlets are scripts with these objects implicit in their scope:
Your script sources can be placed either in your web application's normal web root (allows for subdirectories) or in /WEB-INF/groovy/* (also allows subdirectories).
To make your web application more groovy, you must add the GroovyServlet to your application's web.xml configuration using any mapping you like, so long as it follows the pattern *.* (more on this below). Here is the web.xml entry:
<servlet>
<servlet-name>Groovy</servlet-name>
<servlet-class>groovy.servlet.GroovyServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Groovy</servlet-name>
<url-pattern>*.groovy</url-pattern>
<url-pattern>*.gdo</url-pattern>
</servlet-mapping>
The URL pattern does not require the "*.groovy" mapping. You can, for example, make it more Struts-like but groovy by making your mapping "*.gdo".
| Fields inherited from class | Fields |
|---|---|
class AbstractHttpServlet |
CONTENT_TYPE_TEXT_HTML, INC_PATH_INFO, INC_REQUEST_URI, INC_SERVLET_PATH, INIT_PARAM_RESOURCE_NAME_REGEX, INIT_PARAM_RESOURCE_NAME_REGEX_FLAGS, encoding, namePrefix, reflection, resourceNamePattern, resourceNameReplaceAll, resourceNameReplacement, servletContext, verbose |
| Type Params | Return Type | Name and description |
|---|---|---|
|
protected GroovyScriptEngine |
createGroovyScriptEngine()Hook method to set up the GroovyScriptEngine to use. |
|
public void |
init(ServletConfig config)Initialize the GroovyServlet. |
|
protected boolean |
isVerboseErrors()Whether error responses sent to the client include the script path, the exception message and the top stack frame. |
|
public void |
service(HttpServletRequest request, HttpServletResponse response)Handle web requests to the GroovyServlet |
| Methods inherited from class | Name |
|---|---|
class AbstractHttpServlet |
applyResourceNameMatcher, generateNamePrefixOnce, getResourceConnection, getScriptUri, getScriptUriAsFile, init, removeNamePrefix, setVariables |
Hook method to set up the GroovyScriptEngine to use.
Subclasses may override this method to provide a custom engine.
Initialize the GroovyServlet.
Whether error responses sent to the client include the script path, the
exception message and the top stack frame. false by default, so
internal detail is not disclosed to callers; the full error is written to
the servlet and application logs regardless. Override this method, or set
the groovy.servlet.verbose.errors system property to true,
to re-enable the detailed client responses while debugging.
Handle web requests to the GroovyServlet