NAME
Servlet::GenericServlet - Servlet base class
SYNOPSIS
# usually subclasses will be instantiated instead
my $servlet = Servlet::GenericServlet->new();
$servlet->init($config);
for my $name ($getInitParameterNames()) {
my $value = $servlet->getInitParameter($name);
}
my $config = $servlet->getServletConfig();
my $context = $servlet->getServletContext();
my $info = $servlet->getServletInfo();
my $name = $servlet->getServletName();
$servlet->service($request, $response);
$servlet->log($message, $e);
$servlet->destroy();
DESCRIPTION
Defines a generic, protocol-independent servlet. To write an HTTP servlet, extend Servlet::Http::HttpServlet instead.
Implements the Servlet::Servlet and Servlet::ServletConfig interfaces. May be directly extended by a servlet, although it's more common to extend a protocol-specific subclass.
To write a generic servlet, a developer need only override the service()
method.
CONSTRUCTOR
METHODS
- destroy()
-
Called by the servlet container to indicate to a servlet that the servlet is being taken out of service.
- getInitParameter($name)
-
Returns the value of the named initialization parameter, or undef if the parameter does not exists.
This method is supplied for convenience. It gets the value of the named parameter from the servlet's config object.
Parameters:
- getParameterNames()
-
Returns an array containing the names of the servlet's initialization parameters, or an empty array if the servlet has no initialization parameters.
This method is supplied for convenience. It gets the parameter names from the servlet's config object.
- getServletConfig()
-
Returns this servlet's Servlet::ServletConfig object.
- getServletContext()
-
Returns the Servlet::ServletContext object representing the web application in which the servlet is running.
This method is supplied for convenience. It gets the context from the servlet's config object.
- getServletInfo()
-
Returns information about the servlet, such as author, version, and copyright. By default, this method returns an empty string. Override this method to have it return a meaningful value.
- getServletName()
-
Returns the name of this servlet instance.
- init([$config])
-
Called by the servlet container to indicate to a servlet that the servlet is being placed into service.
This implementation stores the config object it receives from the servlet container for later use. When overriding this method, make sure to call
$self->SUPER::init($config)
Parameters:
Throws:
- log($message, [$e])
-
Writes the specified message (and stack trace, if an optional exception is specified) to the servlet log, prepended by the servlet's name.
Parameters:
- service($request, $response)
-
Called by the servlet container to allow the servlet to respond to a request. Subclasses should override it.
Parameters:
- $request
-
the Servlet::ServletRequest object that contains the client's request
- $response
-
the Servlet::ServletResponse object that contains the servlet's response
Throws:
SEE ALSO
Servlet::ServletConfig, Servlet::ServletContext, Servlet::ServletException, Servlet::Util::Exception
AUTHOR
Brian Moseley, bcm@maz.org