Node:Server-side scripts, Next:Servlets, Up:XML tools
You can take a Kawa program, in any supported language, and run it as either servlet engine (using a web server that supports servlets), or as a "CGI script" on most web servers.
Here is a simple program hello.scm:
(require 'http) ; Required for Scheme, though not BRL/KRL.
(response-content-type 'text/html) ; Optional
(make-element 'p
"The request URL was: " (request-url))
(make-element 'p
(let ((query (request-query-string)))
(if query
(values-append "The query string was: " query)
"There was no query string.")))
#\newline ; emit a new-line at the end
The same program using KRL is shorter:
<p>The request URL was: [(request-url)]</p>,
<p>[(let ((query (request-query-string)))
(if query
(begin ]The query string was: [query)
]There was no query string.[))]</p>
You can also use XQuery:
<p>The request URL was: {request-url()}</p>
<p>{let $query := request-query-string() return
if ($query)
then ("The query string was: ",$query)
else "There was no query string."}</p>
Either way, you compile your program to a servlet:
kawa --servlet -C hello.scmor:
kawa --servlet --krl -C hello.krlor:
kawa --servlet --xquery -C hello.xql
The next two sections will explain how you can install this script as either a servlet or a CGI script.