If you use Cheetah, please support the project and register by clicking here:


14.7 Form input, cookies, session variables and web server variables

General variable tips that also apply to servlets are in section 13.1.

To look up a CGI GET or POST parameter (with POST overriding):

$request.field('myField')     
self.request().field('myField')
These will fail if Webware is not available, because $request (aka self.request() will be None rather than a Webware WebKit.Request object. If you plan to read a lot of CGI parameters, you may want to put the .fields method into a local variable for convenience:
#set $fields = $request.fields
$fields.myField
But remember to do complicated calculations in Python, and assign the results to simple variables in the searchList for display. These $request forms are useful only for occasions where you just need one or two simple request items that going to Python for would be overkill.

To get a cookie or session parameter, subsitute ``cookie'' or ``session'' for ``field'' above. To get a dictionary of all CGI parameters, substitute ``fields'' (ditto for ``cookies''). To verify a field exists, substitute ``hasField'' (ditto for ``hasCookie'').

Other useful request goodies:

## Defined in WebKit.Request
$request.field('myField', 'default value')
$request.time              ## Time this request began in Unix ticks.
$request.timeStamp         ## Time in human-readable format ('asctime' format).
## Defined in WebKit.HTTPRequest
$request.hasField.myField  ## Is a CGI parameter defined?
$request.fields            ## Dictionary of all CGI parameters.
$request.cookie.myCookie   ## A cookie parameter (also .hasCookie, .cookies).
$request.value.myValue     ## A field or cookie variable (field overrides)
                           ## (also .hasValue).
$request.session.mySessionVar  # A session variable.
$request.extraURLPath      ## URL path components to right of servlet, if any.
$request.serverDictionary  ## Dict of environmental vars from web server.
$request.remoteUser        ## Authenticated username.  HTTPRequest.py source
                           ## suggests this is broken and always returns None.
$request.remoteAddress  ## User's IP address (string).
$request.remoteName     ## User's domain name, or IP address if none.
$request.urlPath        ## URI of this servlet.
$request.urlPathDir     ## URI of the directory containing this servlet.
$request.serverSidePath ## Absolute path of this servlet on local filesystem.
$request.serverURL      ## URL of this servlet, without "http://" prefix,
                        ## extra path info or query string.
$request.serverURLDir   ## URL of this servlet's directory, without "http://".
$log("message")         ## Put a message in the Webware server log.  (If you
                        ## define your own 'log' variable, it will override
                        ## this; use $self.log("message") in that case.



Subsections
If you use Cheetah, please support the project and register by clicking here: