Downloading and installing jakarta-tomcat and the jscheme webapp
Downloading the jakarta-tomcat webserver
You can get the latest version of the jakarta-tomcat
webserver from
jakarta.apache.org/tomcat
We will let
CATALINA_HOME
represent the
folder where you have installed the jakarta-tomcat webserver.
Installing the jscheme webapp
Once you've downloaded and unpacked the tomcat server.
Download the jscheme webapp
(
zip or
jar)
and unpack it into the webapp folder of the tomcat server.
Mac OS X, Linux, or Windows98
% cd $CATALINA_HOME
% cd webapps
% jar xvf jschemewebapp.jar
This will create a folder jschemewebapp inside the
webapps
folder
of the
jakarta-tomcat
folder<
Starting the jakarta-tomcat server
Startup the server by setting
JAVA_HOME
to the
home directory of Java on your machine and then giving the
command to start the server. For example, in Linux with the C shell you would use:
Mac OS 10.1.3 or Linux with csh
% cd $CATALINA_HOME
% setenv JAVA_HOME /System/Library/Frameworks/JavaVM/Versions/1.3.1/Home
% bin/startup.sh
LINUX with bash
% cd $CATALINA_HOME
% export JAVA_HOME=usr/java/jdk1.3
% bin/startup.sh
Windows98 in dos window
% cd $CATALINA_HOME
% set JAVA_HOME=C:\jdk1.3
% bin/startup.sh
Note that to start tomcat under Windows you may need to increase the memory allocated to the MSDOS window.
(Do this by right clicking in the upper left corner, then select properties, then memory, then pick the
highest available memory, both intial and default).
Running the demos
Now open a browser and view the demo pages by going to
the URL
http://127.0.0.1:8080/jscheme/test
or
http://localhost:8080/jscheme/test
or
http://yourhost.yourdomain:8080/jscheme/test
and clicking on the "date.servlet" or "mylibdemo.servlet" links.
Adding new content to the jscheme webapp
The jscheme webapp is the folder
$CATALINA_HOME/webapps/jscheme
It contains a folder
WEB-INF
which contains the code defining
the embedding of scheme servlets into tomcat. The files in the WEB-INF folder
are not displayed by the tomcat server. All other files are publically
accessible and the server determines how to process them by the suffix.
Currently the server recognizes three scheme specific suffixes:
.servlet
,
.applet
, and
.javawebstart
.
These are discussed below:
Servlets
Files in the
$CATALINA_HOME/webapps/jscheme
folder
that end in
.servlet
are interpreted as
Scheme programs that will be evaluated to generate the
webpage that will be returned to the client.
Jscheme features an extended syntax (called "quasi-quote")
for simplifying this process.
The "quasi-quote" syntax uses curly braces {}
instead of double quotes "" to represent strings. Moreover,
any scheme expressions inside the {} which are surrounded by
[] are evaluated and converted to strings to be inserted into
the surrounding string.
For example, the date.servlet demo is written using the following
simple code, which shows the use of {} and [] to construct string output.
{
abc
The date is [(Date.)]
}
A slightly more involved example is mylibdemo.servlet
which loads in a library that defines two scheme
procedures "generic-page" and "captioned-image",
and then uses them to construct a page
as follows:
(begin
(load "webapps/jscheme/lib/mylib.scm")
(generic-page
"Demo page for ICFP talk"
"body {background:black;color:white} h1{border: thick solid red}"
{My Pets
[(captioned-image "Snappy and Pepper" "cats.jpg")]
[(captioned-image "Missy" "missy.jpg")]}))
The mylib.scm file is just a scheme program
defining those two procedures as follows:
;; mylib.scm
(define (captioned-image C I)
{
|
[C]
|
})
(define (generic-page Title CSS Body)
{
[Title]
[Body]
})
You can also create applets simply by including scheme
code in a file with the suffix .applet. We will include
more about this later.