Servlet

Abstract servlets

class Servlet.Servlet

Bases: object

A general servlet.

A servlet is a key portion of a server-based application that implements the semantics of a particular request by providing a response. This abstract class defines servlets at a very high level. Most often, developers will subclass HTTPServlet or even Page.

Servlets can be created once, then used and destroyed, or they may be reused several times over (it’s up to the server). Therefore, servlet developers should take the proper actions in awake() and sleep() so that reuse can occur.

Objects that participate in a transaction include:
  • Application

  • Request

  • Transaction

  • Session

  • Servlet

  • Response

The awake(), respond() and sleep() methods form a message sandwich. Each is passed an instance of Transaction which gives further access to all the objects involved.

__init__()

Subclasses must invoke super.

awake(transaction)

Send the awake message.

This message is sent to all objects that participate in the request-response cycle in a top-down fashion, prior to respond(). Subclasses must invoke super.

canBeReused()

Returns whether a single servlet instance can be reused.

The default is True, but subclasses con override to return False. Keep in mind that performance may seriously be degraded if instances can’t be reused. Also, there’s no known good reasons not to reuse an instance. Remember the awake() and sleep() methods are invoked for every transaction. But just in case, your servlet can refuse to be reused.

canBeThreaded()

Return whether the servlet can be multithreaded.

This value should not change during the lifetime of the object. The default implementation returns False. Note: This is not currently used.

close()
log(message)

Log a message.

This can be invoked to print messages concerning the servlet. This is often used by self to relay important information back to developers.

name()

Return the name which is simple the name of the class.

Subclasses should not override this method. It is used for logging and debugging.

open()
respond(transaction)

Respond to a request.

runMethodForTransaction(transaction, method, *args, **kw)
static runTransaction(transaction)
serverSidePath(path=None)

Return the filesystem path of the page on the server.

setFactory(factory)
sleep(transaction)

Send the sleep message.