ResourceConnector
public class GroovyServlet extends AbstractHttpServlet
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".
ServletBinding
,
Serialized FormCONTENT_TYPE_TEXT_HTML, encoding, INC_PATH_INFO, INC_REQUEST_URI, INC_SERVLET_PATH, reflection, resourceNameMatcher, resourceNameReplaceAll, resourceNameReplacement, servletContext, verbose
Constructor | Description |
---|---|
GroovyServlet() |
Modifier and Type | Method | Description |
---|---|---|
protected GroovyScriptEngine |
createGroovyScriptEngine() |
Hook method to setup the GroovyScriptEngine to use.
Subclasses may override this method to provide a custom engine. |
void |
init(javax.servlet.ServletConfig config) |
Initialize the GroovyServlet.
|
void |
service(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response) |
Handle web requests to the GroovyServlet
|
getResourceConnection, getScriptUri, getScriptUriAsFile, setVariables
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log
public void init(javax.servlet.ServletConfig config) throws javax.servlet.ServletException
init
in class AbstractHttpServlet
config
- the servlet configuration provided by the containerjavax.servlet.ServletException
- if this method encountered difficultiesUnavailableException
public void service(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws java.io.IOException
service
in class javax.servlet.http.HttpServlet
request
- the HttpServletRequest
object that
contains the request the client made of
the servletresponse
- the HttpServletResponse
object that
contains the response the servlet returns
to the clientjava.io.IOException
- if an input or output error occurs
while the servlet is handling the
HTTP requestServlet.service(javax.servlet.ServletRequest, javax.servlet.ServletResponse)
protected GroovyScriptEngine createGroovyScriptEngine()