Continuations and Web Applications

Cover page image

Cay S. Horstmann

Continuation

Control Flow in Web Application

Continuation-Based Web Program

Web Programming Basics with Racket

Dynamic HTML

send/suspend

Implementing send/suspend

send/suspend/dispatch

Lab

???

Step 1. Simple Web App

  1. Start Dr. Racket. Paste the following into the top window and hit the Start button.
    #lang web-server/insta
    (define (start request)
      (response/xexpr
       '(html
         (head (title "My Web App"))
         (body (h1 "Under construction")))))

    What happens?

  2. Add a button or link (your choice) to the page that navigates to http://google.com. What is the code of your web app?

Step 2. Adding

  1. We want to put together the app for adding two numbers.  Start with a helper method (mk-number-page prompt url) that generates the Scheme code for
    <html><head><title>Prompt</title>
    <body><form action="URL">
    Prompt<input type="text" name="num"/>
    <input type="submit"/></form></body></html>

    Test your code in the bottom pane.

    What is your function?

  2. Define a function (send-and-get prompt) that can be used as
    (let ((num1 (send-and-get "First number")) ...

    What is your function?

  3. Using this function to show the result, complete the start function of your web application. What is the code of the start function?
    (define (mk-result-page x)
      `(html (body "Result: " ,(number->string x))))
  4. Now test your application. It should add two numbers and show the result.
  5. Use the browser's back button and go to the page prompting for the second input. Type a different number. What sum is computed? How was the first number remembered?

Step 3. Navigation

  1. Add a Start Over link to the result page that goes back to the first page.

    What is your program now?