Chapter 4
Scheme Servlets
In this chapter we explain how to develop interactive web pages. These pages
will typically prompt the user for some information (using a web form or a
hyperlink) and then will generate a new web page, based on the user input.
They may also perform other actions such as read/writing information on the
servers disk, sending email, or accssing a database.
The language we use to specify these interactive web pages is a simple com
bination of Scheme, HTML, and CSS. For most of the examples in this section,
the scheme will be used in relatively simple ways and hence you will not need to
know much about the language itself beyond the few examples we demonstrate
below. In Chapter ??, we will give a full introduction to Scheme and you can
then use that to build even more complex servlets.
4.1
Dynamic Content and Scheme Servlets
The key idea behind servlets is that they provide a way to generate dynamic
webpages, that is webpages in which the HTML is different each time someone
visits it. Servlets can be specified in many different languages. In this book, we
will look closely at servlets specified in Scheme.
To run these servlets you will need to have access to a server which has a
Scheme webapp. The appendix explains how to download and install such a
server. If someone can provide you access to a Scheme server then you will not
need to download and install the server yourself.
Once you have access to a server, you create a scheme servlet simply by
creating a file in the webapp folder and adding the suffix .servlet to the file
name. When someone tries to view that file, the server will read the code that
you have written in the .servlet file and will use that code to generate a new
webpage which is then sent back to the user.
Let us now consider a few simple examples of Scheme servlets. These exam
ples are not very useful by themselves but they allow us to explore the idea
of Scheme servlets in a simpler context. The first example is the following pro
47