58 lines
1.7 KiB
Scheme
58 lines
1.7 KiB
Scheme
(define-structure servlet servlet-interface
|
|
(open servlets
|
|
httpd-requests
|
|
httpd-responses
|
|
url
|
|
scheme-with-scsh)
|
|
(begin
|
|
|
|
(define (get-number input-text . maybe-title)
|
|
(let* ((title (if (pair? maybe-title) (car maybe-title) #f))
|
|
(result (send-html/suspend
|
|
(lambda (new-url)
|
|
`(html ,(if title
|
|
`(title ,title) '())
|
|
(body
|
|
,(if title `(h2 ,title) '())
|
|
(p
|
|
(form (@ (method "get")
|
|
(action ,new-url))
|
|
,input-text
|
|
(input (@ (type "text")
|
|
(name "number"))
|
|
(input (@ (type "submit"))))))
|
|
(hr)
|
|
(p (URL "/" "Return to main menu") (br)
|
|
(URL "add.scm" "Start new calculation."))))))))
|
|
(let* ((bindings (form-query
|
|
(http-url-search (request-url result))))
|
|
(number (string->number
|
|
(extract-single-binding "number" bindings))))
|
|
(if number
|
|
number
|
|
(get-number input-text "Please enter a valid number")))))
|
|
|
|
(define (get-number1)
|
|
(get-number "First number:" "Calculation - Step one"))
|
|
|
|
(define (get-number2)
|
|
(get-number "Second number:" "Calculation - Step two"))
|
|
|
|
(define (main req)
|
|
(let ((req
|
|
(send-html/suspend
|
|
(lambda (new-url)
|
|
`(html (title "Result")
|
|
(body (h1 "Result")
|
|
(p ,(number->string (+ (get-number1) (get-number2))))
|
|
(a (@ (href "add.scm")) "new calculation (new session)")(br)
|
|
(a (@ (href "javascript:history.back(2)")) "new calculation (same session)")(br)
|
|
(a (@ (href ,new-url)) "close this session")))))))
|
|
;; How to clear session data and go to another HTML page:
|
|
(send/finish
|
|
(make-http-error-response http-status/moved-temp req
|
|
"/" "/"))
|
|
))
|
|
; ))
|
|
))
|
|
|