public abstract class AbstractHttpServlet extends HttpServlet
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Modifiers | Name | Description |
---|---|---|
static String |
CONTENT_TYPE_TEXT_HTML |
Content type of the HTTP response. |
static String |
INC_PATH_INFO |
Servlet API include key name: path_info |
static String |
INC_REQUEST_URI |
|
static String |
INC_SERVLET_PATH |
Servlet API include key name: servlet_path |
static String |
INIT_PARAM_RESOURCE_NAME_REGEX |
|
static String |
INIT_PARAM_RESOURCE_NAME_REGEX_FLAGS |
|
protected String |
encoding |
Encoding to use, becomes charset part of contentType. |
protected String |
namePrefix |
a.fink: it was in removeNamePrefix, but was extracted to var for optimization |
protected boolean |
reflection |
Mirrors the static value of the reflection flag in MetaClass. |
protected Pattern |
resourceNamePattern |
Either null or a compiled pattern read from "{@value #INIT_PARAM_RESOURCE_NAME_REGEX}"
and used in AbstractHttpServlet.getScriptUri. |
protected boolean |
resourceNameReplaceAll |
The replace method to use on the matcher. |
protected 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 and description |
---|
AbstractHttpServlet
() Initializes all fields with default values. |
Type | Name and description |
---|---|
protected String |
applyResourceNameMatcher(String uri) |
protected void |
generateNamePrefixOnce() |
URLConnection |
getResourceConnection(String name) Interface method for ResourceContainer. |
protected String |
getScriptUri(HttpServletRequest request) Returns the include-aware uri of the script or template file. |
protected File |
getScriptUriAsFile(HttpServletRequest request) Parses the http request for the real script or template source file. |
void |
init(ServletConfig config) Overrides the generic init method to set some debug flags. |
protected String |
removeNamePrefix(String name) |
protected void |
setVariables(ServletBinding binding) Override this method to set your variables to the Groovy binding. |
Content type of the HTTP response.
Servlet API include key name: path_info
Servlet API include key name: servlet_path
Encoding to use, becomes charset part of contentType.
a.fink: it was in removeNamePrefix, but was extracted to var for optimization
Mirrors the static value of the reflection flag in MetaClass. See AbstractHttpServlet#logGROOVY861
Either null
or a compiled pattern read from "{
The replace method to use on the matcher.
true - replaceAll(resourceNameReplacement); (default) false - replaceFirst(resourceNameReplacement);
The replacement used by the resource name matcher.
Servlet (or the web application) context.
Controls almost all log output.
Interface method for ResourceContainer. This is used by the GroovyScriptEngine.
Returns the include-aware uri of the script or template file.
request
- the http request to analyzeParses the http request for the real script or template source file.
request
- the http request to analyzenull
if the
servlet container cannot translate the virtual path to a real
path for any reason (such as when the content is being made
available from a .war archive).Overrides the generic init method to set some debug flags.
config
- the servlet configuration provided by the containerOverride this method to set your variables to the Groovy 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 modifiedCopyright © 2003-2015 The Apache Software Foundation. All rights reserved.