Servlet::GenericServlet - Servlet base class
# 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();
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.
service()
Does nothing. All of the servlet initialization is done by the init() method.
init()
Called by the servlet container to indicate to a servlet that the servlet is being taken out of service.
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:
the name of the parameter
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.
Returns this servlet's Servlet::ServletConfig object.
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.
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.
Returns the name of this servlet instance.
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)
the Servlet::ServletConfig object that contains configuration information for this servlet
Throws:
if an exception occurs that interrupts the servlet's normal operation
Writes the specified message (and stack trace, if an optional exception is specified) to the servlet log, prepended by the servlet's name.
the error message
an instance of Servlet::Util::Exception (optional)
Called by the servlet container to allow the servlet to respond to a request. Subclasses should override it.
the Servlet::ServletRequest object that contains the client's request
the Servlet::ServletResponse object that contains the servlet's response
if an exception occurs that interferes with the servlet's normal operation
if an input or output exception occurs
Servlet::ServletConfig, Servlet::ServletContext, Servlet::ServletException, Servlet::Util::Exception
Brian Moseley, bcm@maz.org
To install Servlet, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Servlet
CPAN shell
perl -MCPAN -e shell install Servlet
For more information on module installation, please visit the detailed CPAN module installation guide.