| The TclServerTemplate looks for each
<server language="tcl">
tag in an HTML page and treats the following data up to the next
</server> tag as a Tcl script to evaluate.
The reason that Tcl scripts are included in an HTML page is usually
to generate dynamic, server-side content. After running this template,
everything between and including the <server> and
</server> tags is replaced with the result of
evaluating the Tcl script as follows:
- Anything printed to the standard output of the Tcl interpreter is
added to the HTML document (for instance,
puts "hello" ).
- Additionally, if the Tcl script returns a value, that value is
added to the HTML document (for instance,
return "bob" ).
Multiple puts and a final return can both be
used within a single Tcl fragment.
All Tcl fragments within a given page are evaluated in the same Tcl
interpreter. The Tcl interpreter actually lives for the entire duration
of this Template object, so the user can implement
persistence across requests.
The following configuration parameters are used to initialize this
template.
- script
- The name of the Tcl script to evaluate when the interpreter is
created. This script only evaluated when the interp is created,
not on every request. The variables
prefix and
server are set before this file is evaluated, and
are references to the parameters passed to a handler
init method.
- root
- The document root, if the script is a relative file name.
If the "root" property under the template prefix is not found, the
global "root" property is used. If the global "root" property is
not found, the current directory is used.
- debug
- If this configuration parameter is present, this class
replaces the
<server> and
</server> tags with comments, so the user
can keep track of where the dynamically generated content is coming
from by examining the comments in the resultant HTML document.
By default, the <server> and
</server> are completely eliminated from the
HTML document rather than changed into comments.
Before evaluating each HTML document, this class variables
in the Tcl interpreter, which can be used to interact back with Java to
do things like set the response headers:
- request
- Exposes the
sunlabs.brazil.server.Request Java object.
It is set anew at each request.
- prefix
- Exposes the handler prefix String.
- server
- Exposes the handler
sunlabs.brazil.server.Server object.
- SessionId
- Exposes the session id for this interp, or "none".
If a serialized version of this object is reconstituted, the init
method must be called again.
author: Colin Stevens (colin.stevens@sun.com) version: 1.17, 00/12/11 |