|
Groovy Documentation | |||||||
FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object javax.servlet.http.HttpServlet groovy.servlet.AbstractHttpServlet
public abstract class AbstractHttpServlet extends HttpServlet
A base class dealing with common HTTP servlet API housekeeping aspects.
resource.name.regex = empty - defaults to null resource.name.replacement = empty - defaults to null resource.name.replace.all = true (default) | false means replaceFirst()Note: If you specify a regex, you have to specify a replacement string too! Otherwise an exception gets raised.
verbose = false(default) | trueIn order to support class-loading-troubles-debugging with Tomcat 4 or higher, you can log the class loader responsible for loading some classes. See GROOVY-861 for details. The servlet init parameter name is:
log.GROOVY861 = false(default) | trueIf you experience class-loading-troubles with Tomcat 4 (or higher) or any other servlet container using custom class loader setups, you can fallback to use (slower) reflection in Groovy's MetaClass implementation. Please contact the dev team with your problem! Thanks. The servlet init parameter name is:
reflection = false(default) | true
Field Summary | |
---|---|
static java.lang.String |
CONTENT_TYPE_TEXT_HTML
Content type of the HTTP response. |
static java.lang.String |
INC_PATH_INFO
Servlet API include key name: path_info |
static java.lang.String |
INC_REQUEST_URI
|
static java.lang.String |
INC_SERVLET_PATH
Servlet API include key name: servlet_path |
protected java.lang.String |
encoding
Encoding to use, becomes charset part of contentType. |
protected boolean |
reflection
Mirrors the static value of the reflection flag in MetaClass. |
protected java.util.regex.Matcher |
resourceNameMatcher
Either |
protected boolean |
resourceNameReplaceAll
The replace method to use on the matcher. |
protected java.lang.String |
resourceNameReplacement
The replacement used by the resource name matcher. |
protected ServletContext |
servletContext
Servlet (or the web application) context. |
protected boolean |
verbose
Controls almost all log output. |
Constructor Summary | |
AbstractHttpServlet()
Initializes all fields with default values. |
Method Summary | |
---|---|
java.net.URLConnection
|
getResourceConnection(java.lang.String name)
Interface method for ResourceContainer. |
protected java.lang.String
|
getScriptUri(HttpServletRequest request)
Returns the include-aware uri of the script or template file. |
protected java.io.File
|
getScriptUriAsFile(HttpServletRequest request)
Overrides the generic init method to set some debug flags. |
void
|
init(ServletConfig config)
|
protected void
|
setVariables(ServletBinding binding)
Override this method to set your variables to the Groovy binding. |
Field Detail |
---|
public static final java.lang.String CONTENT_TYPE_TEXT_HTML
public static final java.lang.String INC_PATH_INFO
public static final java.lang.String INC_REQUEST_URI
public static final java.lang.String INC_SERVLET_PATH
protected java.lang.String encoding
protected boolean reflection
protected java.util.regex.Matcher resourceNameMatcher
null
or a compiled pattern matcher read from "resource.name.regex"
and used in AbstractHttpServlet#getScriptUri(HttpServletRequest)#getScriptUri(HttpServletRequest).
protected boolean resourceNameReplaceAll
true - replaceAll(resourceNameReplacement); (default) false - replaceFirst(resourceNameReplacement);
protected java.lang.String resourceNameReplacement
protected ServletContext servletContext
protected boolean verbose
Constructor Detail |
---|
public AbstractHttpServlet()
Method Detail |
---|
public java.net.URLConnection getResourceConnection(java.lang.String name)
protected java.lang.String getScriptUri(HttpServletRequest request)
request
- the http request to analyze
protected java.io.File getScriptUriAsFile(HttpServletRequest request)
config
- the servlet configuration provided by the container
public void init(ServletConfig config)
protected void setVariables(ServletBinding binding)
All variables bound the binding are passed to the template source text, e.g. the HTML file, when the template is merged.
The binding provided by TemplateServlet does already include some default variables. As of this writing, they are (copied from ServletBinding):
And via implicit hard-coded keywords:
The binding also provides convenient methods:
Example binding all servlet context variables:
class MyServlet extends TemplateServlet {
protected void setVariables(ServletBinding binding) {
// Bind a simple variable
binding.setVariable("answer", new Long(42));
// Bind all servlet context attributes...
ServletContext context = (ServletContext) binding.getVariable("context");
Enumeration enumeration = context.getAttributeNames();
while (enumeration.hasMoreElements()) {
String name = (String) enumeration.nextElement();
binding.setVariable(name, context.getAttribute(name));
}
}
}
binding
- to be modified
Groovy Documentation