You are writing a servlet in the PLT web server and want to choose an action based on which link was clicked.
If you want to embed the callbacks in an Xexpr, you can use
send/suspend/callback, Simply insert your callbacks (functions of single argument, a request) in the Xexpr, and
send/suspend/callback will replace them with appropriate URLs. For example:
(define (callback request)
`(html (head (title "page two"))
(body (h1 "page two"))))
(send/suspend/callback
`(html (head (title "page one"))
(body (h1 "page one")
(p (a ((href ,callback)) "page two")))))
If you want access to the generated URLs, for example to use in Javascript, use
send/suspend/dispatch.
send/suspend/dispatch takes a function of a single argument. The argument, which by convention is named
embed/url, is a function that consumes a callaback and returns a URL. For example:
(define (callback request)
`(html (head (title "page two"))
(body (h1 "page two"))))
(send/suspend/dispatch
(lambda (embed/url)
`(html (head (title "page one"))
(body (h1 "page one")
(p (a ((href ,(embed/url callback))) "page two"))))))
It is not commonly realised that there can be more than one continuation per page.
send/suspend/dispatch and
send/suspend/callback show that this is possible. Both are provided by the
servlet.ss module in the
web-server collection.
A clumsy way to handle this situation is to append a parameter to the URL:
`(a ((href ,(string-append url "?arg=suchandsuch"))) "click here")
This is not recommended: the web server will add this parameter to all the next 'continuation' URL it gives you and you will have to manually strip it out.
The paper detailing
send/suspend/dispatch (on which
send/suspend/callback is built) is available from:
http://continue.cs.brown.edu/research/
--
NoelWelsh - 31 Aug 2004
--
PeteHopkins - 23 Nov 2004
--
DanielSilva - 11 Jan 2005