The Servlet Object

The servlet object is created when the servlet is initialized. The servlet object holds various servlet information and initialisation properties as well as the servlet context object.

Shown below is the servlet object prototype chain.

The servlet object is of class Servlet.

Using the Servlet Object

The servlet properties and functions are simply accessed by prefixing with ‘servlet’ as follows.

var si = servlet.info ;

servlet.log("log this message to the servlet log file");

The context property is the servlet context object, which itself has properties and functions and therefore is dealt with separately (see context object).

The params property which contains the servlet initialisation parameters is held as an array of objects. The array as a whole can be accessed as above or access to an individual parameter would be as follows

var key = servlet.params.installation_key.

Servlet Object Properties

All predefined properties are read-only and can not be changed by the script.

Property

Description

info

A string that details the servlets name and version number.

context

The servlet context object properties (see below).

params

The parameters that have been passed to the servlet at initialisation from the web.xml initialisation file in the form <init-param> …

</init-param>. These will be in the form of an array of script objects.

accessCount

A counter which records the number of pages accessed during the servlets uptime.

loadErrorCount

A counter which records the number of load errors encountered during the servlets uptime.

runtimeErrorCount

A counter which records the number of runtime errors encountered during the servlets uptime.

notFoundCount

A counter which records the number of page not found errors encountered during the servlets uptime.

uptime

The period of time in seconds, which the servlet has been running.

Servlet Object Functions

Function

Description

log(message)

Writes the specified string ‘message’ to a servlet log file, prepended by the servlets name.

 

Comment on this topic

Topic ID: 150108