|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectjavax.servlet.GenericServlet
javax.servlet.http.HttpServlet
groovy.servlet.TemplateServlet
A generic servlet for templates.
It wraps a groovy.text.TemplateEngine to process HTTP
requests. By default, it uses the
groovy.text.SimpleTemplateEngine which interprets JSP-like (or
Canvas-like) templates.
Example HelloWorld.template:
<html>
<body>
<% 3.times { %>
Hello World!
<% } %>
</body>
</html>
true.
bindDefaultVariables = init("bindDefaultVariables", false);
bindRequestParameters = init("bindRequestParameters", false);
| Field Summary | |
static java.lang.String |
DEFAULT_CONTENT_TYPE
|
private javax.servlet.ServletContext |
servletContext
|
protected TemplateEngine |
templateEngine
|
| Fields inherited from class javax.servlet.http.HttpServlet |
|
| Fields inherited from class javax.servlet.GenericServlet |
|
| Constructor Summary | |
TemplateServlet()
|
|
| Method Summary | |
protected TemplateEngine |
createTemplateEngine(javax.servlet.ServletConfig config)
Creates the template engine. |
void |
doGet(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Delegates to doRequest(HttpServletRequest, HttpServletResponse). |
void |
doPost(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Delegates to doRequest(HttpServletRequest, HttpServletResponse). |
protected void |
doRequest(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Processes all requests by dispatching to helper methods. |
protected void |
error(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
java.lang.Exception exception)
Simply sends an internal server error page (code 500). |
protected Template |
getTemplate(javax.servlet.http.HttpServletRequest request)
Gets the template by its name. |
protected Template |
getTemplate(java.net.URL templateURL)
Gets the template by its url. |
protected Template |
handleRequest(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
Binding binding)
Default request handling. |
void |
init(javax.servlet.ServletConfig config)
Initializes the servlet. |
protected boolean |
init(javax.servlet.ServletConfig config,
java.lang.String param,
boolean value)
Convient evaluation of boolean configuration parameters. |
protected void |
merge(Template template,
Binding binding,
javax.servlet.http.HttpServletResponse response)
Merges the template and writes response. |
protected void |
requestDone(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
Binding binding)
Called one request is processed. |
protected java.net.URL |
resolveTemplateName(java.lang.String templateName)
Locate template and convert its location to an URL. |
protected void |
setContentType(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Sets DEFAULT_CONTENT_TYPE. |
| Methods inherited from class javax.servlet.http.HttpServlet |
doDelete, doHead, doOptions, doPut, doTrace, getLastModified, service, service |
| Methods inherited from class javax.servlet.GenericServlet |
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
public static final java.lang.String DEFAULT_CONTENT_TYPE
private javax.servlet.ServletContext servletContext
protected TemplateEngine templateEngine
| Constructor Detail |
public TemplateServlet()
| Method Detail |
public void init(javax.servlet.ServletConfig config)
config - Passed by the servlet container.
protected boolean init(javax.servlet.ServletConfig config,
java.lang.String param,
boolean value)
config - Servlet configuration passed by the servlet container.param - Name of the paramter to look up.value - Default value if parameter name is not set.
true or false.protected TemplateEngine createTemplateEngine(javax.servlet.ServletConfig config)
init(ServletConfig) and returns just
SimpleTemplateEngine() if the init parameter templateEngine
is not set.
config - This serlvet configuration passed by the container.
createTemplateEngine(javax.servlet.ServletConfig)
public void doGet(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
throws javax.servlet.ServletException,
java.io.IOException
doRequest(HttpServletRequest, HttpServletResponse).
javax.servlet.ServletException
java.io.IOException
public void doPost(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
throws javax.servlet.ServletException,
java.io.IOException
doRequest(HttpServletRequest, HttpServletResponse).
javax.servlet.ServletException
java.io.IOException
protected void doRequest(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
throws javax.servlet.ServletException
request - The http request.response - The http response.
javax.servlet.ServletException - ...
protected void setContentType(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
DEFAULT_CONTENT_TYPE.
request - The HTTP request.response - The HTTP response.
protected Template handleRequest(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
Binding binding)
throws java.lang.Exception
request - The HTTP request.response - The HTTP response.binding - The application context.
java.lang.Exception
protected Template getTemplate(javax.servlet.http.HttpServletRequest request)
throws java.lang.Exception
request - The HttpServletRequest.
java.lang.Exception - Any exception.
protected java.net.URL resolveTemplateName(java.lang.String templateName)
throws java.lang.Exception
templateName - The name of the template.
java.lang.Exception - Any exception.
protected Template getTemplate(java.net.URL templateURL)
throws java.lang.Exception
templateURL - The url of the template.
java.lang.Exception - Any exception.
protected void merge(Template template,
Binding binding,
javax.servlet.http.HttpServletResponse response)
throws java.lang.Exception
template - The template that will be merged... now!binding - The application context.response - The HTTP response.
java.lang.Exception - Any exception.
protected void error(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
java.lang.Exception exception)
request - The HTTP request.response - The HTTP response.exception - The cause.
protected void requestDone(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
Binding binding)
request - The HTTP request.response - The HTTP response.binding - The application context.
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||