; Minimal servlet for getting information out of a request ; and storing what's been done. ; This is a magical incantation that makes this file a servlet ; and gives access to useful servlet functionality (require (lib "unitsig.ss") (lib "servlet-sig.ss" "web-server")) (unit/sig () (import servlet^) ; Here is where the interesting code actually starts. (report-errors-to-browser send/finish) ; Get all the responses seen so far. (define (get-responses-list) (if (file-exists? "all-requests-to-respond") (let* ((port (open-input-file "all-requests-to-respond")) (responses-list (read port))) (close-input-port port) (if (eof-object? responses-list) '() responses-list)) '())) ; Write all the responses seen so far (define (write-responses-list rl) (let ((port (open-output-file "all-requests-to-respond" 'replace))) (write rl port) (close-output-port port))) ; Add the current response to the list of stored responses (define (store-current-request q r) (write-responses-list (cons (list q r) (get-responses-list)))) ; Get the bindings from the request (let ((my-bindings (request-bindings initial-request))) (cond ; make sure q is defined [(not (exists-binding? 'q my-bindings)) '(html (head (title "Error")) (body ((bgcolor "red")) (p "This page needs you to define q!")))] ; make sure r is defined [(not (exists-binding? 'r my-bindings)) '(html (head (title "Error")) (body ((bgcolor "blue")) (p "This page needs you to define r!")))] ; use the values of q and r to construct a new page [else (let* ((q (car (extract-bindings 'q my-bindings))) (r (car (extract-bindings 'r my-bindings)))) (store-current-request q r) `(html (head (title "Relationships")) (body ([bgcolor "white"]) (p "Every " ,q " is a " ,r "."))))])))