Servlet::ServletContext - servlet context interface
for my $name ($context->getAttributeNames()) { my $value = $context->getAttribute($name); $context->removeAttribute($name); $cnotext->setAttribute($name, $value); }
my $context = $context->getContext($uripath);
for my $name ($context->getInitParameterNames()) { my $value = $context->getInitParameter($name); }
for my $uripath ($context->getResourcePaths()) { my $url = $context->getResource($uripath); my $handle = $context->getResourceAsHandle($uripath); my $realpath = $context->getRealPath($uripath); my $dispatcher = $context->getRequestDispatcher($uripath); }
my $type = $context->getMimeType($file);
my $dispatcher = $context->getNamedDispatcher($name);
my $major = $context->getMajorVersion(); my $minor = $context->getMinorVersion(); my $info = $context->getServerInfo(); my $name = $context->getServletContextName();
$contxt->log($message, $e);
Defines a set of methods that a servlet uses to communicate with its servlet container, for example, to get the MIME type of a file, dispatch requests, or write to a log file.
There is one context per web application per Perl interpreter. A ``web application'' is a collection of servlets and content installed under a specific subset of the server's URL namespace.
In the case of a web application marked ``distributed'' in its deployment descriptor, there will be one context instance for each interpreter. In this situation, the context cannot be used as a location to share global information (because the information won't truly be global). Use an external resource like a database instead.
The Servlet::ServletContext object is contained within the Servlet::ServletConfig object, which the servlet container provides the servlet when the servlet is initialized.
getAttribute($name)
getAttributeNames()
.
The attribute is returned as a Perl scalar or reference. Attribute names should follow the same convention as package names. The Servlet API specification reserves names matching main::*, CORE::*, UNIVERSAL::*, and any other standard reserved package names.
Parameters:
getAttributeNames()
getContext($uripath)
This method allows servlets to gain access to the context for various parts of the server, and as needed obtain Servlet::RequestDispatcher objects from the context. The given path must be absolute (beginning with '/') and is intepreted based on the server's document root.
In a security conscious environment, the servlet container may return undef for a given URL.
Parameters:
getInitParameter($name)
This method can make available configuration information useful to an entire web application. for example, it can provide a webmaster's email address or the name of a system that holds critical data.
Parameters:
getInitParameterNames()
getMajorVersion()
getMimeType($file)
Parameters:
getMinorVersion()
getNamedDispatcher($name)
Servlets may be given names via server administration or via a web
appliation deployment descriptor. A servlet instance can determine its
name using getServletName()
.
Parameters:
getRealPath($uripath)
The real path returned will be in a form appropriate to the computer and operating system on which the servlet container is running, including the proper path separators.
Parameters:
getRequestDispatcher($uripath)
The uripath must begin with a '/' and is interpreted as relative to
the current context root. Use getContext()
to obtain a dispatcher
for resources in foreign contexts.
Parameters:
getResource($uripath)
This method allows the servlet container to make a resource available to servlets from any source. Resources can be located on a local or remote file system, in a database, etc.
The servlet container must implement any objects that are necessary to access the resource.
The resource content is returned directly in an unprocessed form. Use a Servlet::RequestDispatcher instead to include results of an execution.
Parameters:
getResourceAsHandle($uripath)
The data in the filehandle can be of any type or length. The uri path
must be specified according to the rules given in getResource()
.
Meta-information such as content length and content type that is
available via getResource()
is lost when using this method.
The servlet container must implement any objects that are necessary to access the resource.
Parameters:
getResourcePaths()
getServerInfo()
The form of the returned string is servername/versionnumber. For example:
Wombat/1.0
The servlet container may return other optional information after the primary string in parentheses. For example:
Wombat/1.0 (perl 5.6.0; Linux 2.2.18 i686)
getServletContextName()
Parameters:
removeAttribute($name)
getAttribute()
to
retrieve the attribute's value will return undef.
Parameters:
See getAttribute()
for details on attribute naming.
Parameters:
the IO::Handle manpage, the Servlet::GenericServlet manpage, the Servlet::RequestDispatcher manpage, the Servlet::ServletConfig manpage, the Servlet::Util::Exception manpage
Brian Moseley, bcm@maz.org