[plt-scheme] State and "Save as servlet"

From: Jens Axel Søgaard (jensaxel at soegaard.net)
Date: Sat Feb 22 17:27:14 EST 2003

I am in the proces of rewriting some of my old servlets,
in order to use them in my class. The following is a little
servlet, that keeps track of the number of visits to the page:

(require
   (lib "unitsig.ss")
   (lib "servlet-sig.ss" "web-server"))

(define counter 0)   ; once, when the servlet is loaded from disk

(unit/sig ()
   (import servlet^)

  ; each time the servlets is called
  (set! counter (+ counter 1))

  `(html (head (title "Counter"))
         (body ([bgcolor "white"])
               (p "This page has been viewed "
                  ,(number->string counter)
                  " times."))))

I have taught my students that the way to write a servlet is to
write a program, that generates xml. Then use "Save as servlet".
The "Save as servlet" stuff wraps (unit/sig () ... ) around the
program and saves it in the servlet directory ready for use.

My problem is that I can't figure out how to write this program
within the restrictions of the "Advanced Student Language".
(I can't save the state of counter in a file, since the advanced
language supports in- and output from the repl only).

Have I missed something obvious?

--
Jens Axel Søgaard



Posted on the users mailing list.