a simple adding servlet; doing a lot by hand
This commit is contained in:
parent
0b2a59b6ef
commit
fba9e1a4d3
|
@ -0,0 +1,54 @@
|
|||
(define-structure plugin plugin-interface
|
||||
(open plugin-utilities
|
||||
httpd-request
|
||||
url
|
||||
scsh
|
||||
scheme)
|
||||
(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 `(h1 ,title) '())
|
||||
(p (a (@ href "reset") "click here to reset server's plugin cache"))
|
||||
(p
|
||||
(form (@ (method "get")
|
||||
(action ,new-url))
|
||||
,input-text
|
||||
(input (@ (type "text")
|
||||
(name "number"))
|
||||
(input (@ (type "submit"))))))))))))
|
||||
(let* ((bindings (form-query
|
||||
(http-url:search (request:url result))))
|
||||
(number (string->number
|
||||
(extract-single-binding bindings "number"))))
|
||||
(if number
|
||||
number
|
||||
(get-number input-text "Please enter a number")))))
|
||||
|
||||
(define (get-number1)
|
||||
(get-number "First number:"))
|
||||
|
||||
(define (get-number2)
|
||||
(get-number "Second number:"))
|
||||
|
||||
(define (main req)
|
||||
(let ((number1 (get-number1))
|
||||
(number2 (get-number2)))
|
||||
(send-html/suspend
|
||||
(lambda (new-url)
|
||||
`(html (title "Result")
|
||||
(body (h1 "Result")
|
||||
(p ,(number->string (+ number1 number2)))
|
||||
(a (@ (href ,new-url)) "done")))))
|
||||
(send-html/finish '(html
|
||||
(title "Finished")
|
||||
(body (h1 "Finished")
|
||||
(a (@ href "/") "yoh."))))))
|
||||
; ))
|
||||
))
|
||||
|
Loading…
Reference in New Issue