Servlet::GenericServlet - Servlet base class

- NAME
- SYNOPSIS
- DESCRIPTION
- CONSTRUCTOR
- METHODS
- SEE ALSO
- AUTHOR

# 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

`new()`
  Does nothing. All of the servlet initialization is done by the `init()` method.

# 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:

  $name
    the name of the parameter

`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:

  $config
    the Servlet::ServletConfig object that contains configuration information for this servlet

  Throws:

  Servlet::ServletException
    if an exception occurs that interrupts the servlet's normal operation

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:

  $message
    the error message

  $e
    an instance of Servlet::Util::Exception (optional)

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:

  Servlet::ServletException
    if an exception occurs that interferes with the servlet's normal operation

  Servlet::Util::IOException
    if an input or output exception occurs

# SEE ALSO

the Servlet::ServletConfig manpage, the Servlet::ServletContext manpage, the Servlet::ServletException manpage, the Servlet::Util::Exception manpage

# AUTHOR

Brian Moseley, bcm@maz.org