1 Nov 2001Yale1 Programming Interactive Web Scripts Matthias Felleisen Northeastern University.

Slides:



Advertisements
Similar presentations
Chapter 6 Server-side Programming: Java Servlets
Advertisements

!""""""" "# $t+ W Tl+% $Oo+ OoVo% $ Mo+ Mo+% $+ Q + + % $ + PpBv+% $+ N +n+ % $pP + PpP% $+ +rKb+r% /((((((( () !""""""" "# $t+ W Tl+% $Oo+ OoVo% $ Mo+
PHP I.
Compiling Web Scripts for Apache Jacob Matthews Luke Hoban Robby Findler Rice University.
How Many Continuations can Dance on the Head of a Pin Matthias Felleisen King of Continuations and Professor of Computer Science.
Programming the Interactive Web Shriram Krishnamurthi Brown University.
DT228/3 Web Development WWW and Client server model.
Browsers and Servers CGI Processing Model ( Common Gateway Interface ) © Norman White, 2013.
CS 290C: Formal Models for Web Software Lecture 10: Language Based Modeling and Analysis of Navigation Errors Instructor: Tevfik Bultan.
Fast Track to ColdFusion 9. Getting Started with ColdFusion Understanding Dynamic Web Pages ColdFusion Benchmark Introducing the ColdFusion Language Introducing.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 34 Servlets.
Active Server Pages Chapter 1. Introduction Understand how browsers and servers interacted when the Web was young Understand what early Internet and intranet.
1 CS6320 – Why Servlets? L. Grewe 2 What is a Servlet? Servlets are Java programs that can be run dynamically from a Web Server Servlets are Java programs.
Definitions, Definitions, Definitions Lead to Understanding.
ASP.NET 2.0 Chapter 6 Securing the ASP.NET Application.
Java web development Servlet & Java server pages.
Java Servlets. What Are Servlets? Basically, a java program that runs on the server Basically, a java program that runs on the server Creates dynamic.
Quick Tour of the Web Technologies: The BIG picture LECTURE A bird’s eye view of the different web technologies that we shall explore and study.
Christopher M. Pascucci Basic Structural Concepts of.NET Browser – Server Interaction.
Overview of JSP Technology. The need of JSP With servlets, it is easy to – Read form data – Read HTTP request headers – Set HTTP status codes and response.
DAT602 Database Application Development Lecture 15 Java Server Pages Part 1.
Sys Prog & Scripting - HW Univ1 Systems Programming & Scripting Lecture 15: PHP Introduction.
INTRODUCTION TO WEB DATABASE PROGRAMMING
1 Homework / Exam Exam 3 –Solutions Posted –Questions? HW8 due next class Final Exam –See posted schedule Websites on UNIX systems Course Evaluations.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Applets & Servlets.
FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Part 4 Web technologies: HTTP, CGI, PHP,Java applets)
Dynamic Web Sites Chris North cs3724: HCI. Presentations matt ketner, sam altman, mike gordon Vote: UI Hall of Fame/Shame?
Dynamic Web Pages (Flash, JavaScript)
Comp2513 Forms and CGI Server Applications Daniel L. Silver, Ph.D.
Basics of Web Databases With the advent of Web database technology, Web pages are no longer static, but dynamic with connection to a back-end database.
Chapter 16 The World Wide Web. 2 The Web An infrastructure of information combined and the network software used to access it Web page A document that.
9 Chapter Nine Compiled Web Server Programs. 9 Chapter Objectives Learn about Common Gateway Interface (CGI) Create CGI programs that generate dynamic.
CS4273: Distributed System Technologies and Programming I Lecture 7: Java Networking.
Java CGI Lecture notes by Theodoros Anagnostopoulos.
10/13/2015 ©2006 Scott Miller, University of Victoria 1 Content Serving Static vs. Dynamic Content Web Servers Server Flow Control Rev. 2.0.
Chapter 3 Servlet Basics. 1.Recall the Servlet Role 2.Basic Servlet Structure 3.A simple servlet that generates plain text 4.A servlet that generates.
Chapter 6 Server-side Programming: Java Servlets
CGI Common Gateway Interface. CGI is the scheme to interface other programs to the Web Server.
1 CS122B: Projects in Databases and Web Applications Spring 2015 Notes 03: Web-App Architectures Professor Chen Li Department of Computer Science CS122B.
1 MSCS 237 Overview of web technologies (A specific type of distributed systems)
Overview Web Session 3 Matakuliah: Web Database Tahun: 2008.
® IBM Software Group © 2007 IBM Corporation Best Practices for Session Management
Copyright © 2002 ProsoftTraining. All rights reserved. JavaServer Pages.
Saving State on the WWW. The Issue  Connections on the WWW are stateless  Every time a link is followed is like the first time to the server — it has.
6 Feb 2002PL Day1 Programming Interactive Web Scripts Matthias Felleisen PLT.
David Lawrence 7/8/091Intro. to PHP -- David Lawrence.
Jan 2001C.Watters1 World Wide Web and E-Commerce Client Side Processing.
1 Java Servlets l Servlets : programs that run within the context of a server, analogous to applets that run within the context of a browser. l Used to.
Middleware 3/29/2001 Kang, Seungwoo Lee, Jinwon. Description of Topics 1. CGI, Servlets, JSPs 2. Sessions/Cookies 3. Database Connection(JDBC, Connection.
JS (Java Servlets). Internet evolution [1] The internet Internet started of as a static content dispersal and delivery mechanism, where files residing.
Module: Software Engineering of Web Applications Chapter 2: Technologies 1.
CSI 3125, Preliminaries, page 1 SERVLET. CSI 3125, Preliminaries, page 2 SERVLET A servlet is a server-side software program, written in Java code, that.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
 Before you continue you should have a basic understanding of the following:  HTML  CSS  JavaScript.
Java Programming: Advanced Topics 1 Building Web Applications Chapter 13.
1 Chapter 22 World Wide Web (HTTP) Chapter 22 World Wide Web (HTTP) Mi-Jung Choi Dept. of Computer Science and Engineering
World Wide Web has been created to share the text document across the world. In static web pages the requesting user has no ability to interact with the.
JavaScript Invented 1995 Steve, Tony & Sharon. A Scripting Language (A scripting language is a lightweight programming language that supports the writing.
Lesson 11. CGI CGI is the interface between a Web page or browser and a Web server that is running a certain program/script. The CGI (Common Gateway Interface)
CS122B: Projects in Databases and Web Applications Spring 2017
CS122B: Projects in Databases and Web Applications Winter 2017
WWW and HTTP King Fahd University of Petroleum & Minerals
PHP / MySQL Introduction
Dynamic Web Pages (Flash, JavaScript)
Chapter 26 Servlets.
CS122B: Projects in Databases and Web Applications Winter 2018
CS122B: Projects in Databases and Web Applications Spring 2018
CS122B: Projects in Databases and Web Applications Winter 2019
Web Application Development Using PHP
Presentation transcript:

1 Nov 2001Yale1 Programming Interactive Web Scripts Matthias Felleisen Northeastern University

1 Nov 2001Yale2 Web Scripts What is a CGI script (servlet)? What are the new problems of CGI scripts? Inventing a new language/server Using FP techniques to solve the problems in existing context

1 Nov 2001Yale3 Interactive Web Scripts USA Today says: “… more than half the pages on the Web are generated on demand.” (july 2000) Technology: –CGI –Java Servlets –Active Server Pages, Java Server Pages

1 Nov 2001Yale4 Interactive Web Scripts current information about server connection to up-to-date database determining consumer information on-line experiments games … and many more reasons Why generate Web pages on demand?

1 Nov 2001Yale5 Programming Interactive Scripts: Today

1 Nov 2001Yale6 Interactive Web Scripts a cgi script writes a page, terminates to prompt the consumer, it writes a form and terminates when the consumer replies, another (portion of the) script reads the form and performs the next step

1 Nov 2001Yale7 Interactive Web Scripts: Hello World (output-http-headers) (write-xml/content (xexpr->xml '(html (title "My First CGI Page") (body "Hello World")))) (printf "My First CGI Page~n”) (printf "Hello World")

1 Nov 2001Yale8 Interactive Web Scripts: Status (output-http-headers) (write-xml/content (xexpr->xml `(html (title "My Second CGI Page") (body (h1 "Server Status") (br),(read-line (car (process "uptime"))))))) (printf ”Server Status: ~a~n" (read-line (car (process "uptime")))))))

1 Nov 2001Yale9 Interactive Web Scripts: Multiply by 10 (output-http-headers) (define (get-number) … bindings …) (write-xml/content (xexpr->xml `(html (title "The Multiply-by-10 Page") (body "the result is: ",(* 10 (get-number))))))) (printf "the result is: ~a" (* (get-number) 10)) (define (get-number) (printf "Enter a number ") (flush-output) (read))

1 Nov 2001Yale10 Interactive Web Scripts: Multiply by 10 (define (get-number) (printf "Enter a number ") (flush-output) (read)) (printf "the result is: ~a" (* (get-number) (get-number))) (output-http-headers) (define (get-number).. binding …) (write-xml/content (xexpr->xml `(html (title "The Multiply Page") (body "the result is ",(* (get-number) (get-number)))))))

1 Nov 2001Yale11 Interactive Web Scripts: Multiply (Page 1) Multiply Multiply <form method="get" action="

1 Nov 2001Yale12 Interactive Web Scripts: cgi-first.ss (output-http-headers) (write-xml/content (xexpr->xml `(html (title "The Multiply Page") (body (form ([method "get"][action " (p "Enter the second number: ") (input ([type "hidden"][name "first"] [value,(get-number)])) (input ([type "text"] [name "second"][value "1"])))))))

1 Nov 2001Yale13 Interactive Web Scripts: Multiply (Page 2) The Multiply Page Enter the second number: <form method="get" action="

1 Nov 2001Yale14 Interactive Web Scripts: cgi-second.ss (output-http-headers) (write-xml/content (xexpr->xml `(html (title "The Multiply Page") (body "the result is: ",(* (get-number 'first) (get-number 'second))))))))

1 Nov 2001Yale15 Interacting with Web Scripts

1 Nov 2001Yale16 Interacting with Web Scripts

1 Nov 2001Yale17 Interacting with Web Scripts

1 Nov 2001Yale18 Interacting with Web Scripts.. and back:

1 Nov 2001Yale19 Interacting with Web Scripts

1 Nov 2001Yale20 Interactive Web Scripts and Continuations (define multiply (lambda (x y) (* x y))) (define multiply (lambda (x) (lambda (y) (* x y)))) (define multiply-by-22 (lambda (y) (* 22 y)))

1 Nov 2001Yale21 Interactive Web Scripts and Continuations cgi scriptconsumer cgi scriptconsumer the back button

1 Nov 2001Yale22 Interactive Web Scripts and Continuations cgi scriptconsumer cgi scriptconsumer the back button cloning

1 Nov 2001Yale23 Interactive Web Scripts and Continuations

1 Nov 2001Yale24 Interactive Web Scripts and Continuations search first leg search second leg search … leg … start restart

1 Nov 2001Yale25 Interactive Web Scripts and Continuations Christian Queinnec, ICFP’00 The back button turns cgi scripts into coroutines with multiply resumable interaction points. Each interaction represents a continuation grabbed and saved for future resumption by the consumer.

1 Nov 2001Yale26 Interactive Web Scripts and Continuations Corollary: Scripting languages should support resumable continuations so that programmers don’t have to implement them by hand.

1 Nov 2001Yale27 The Custom Server Solution Graunke, Krishnamurthi, Felleisen: “Programming the Web with High- Level Programming Languages”. European Symposium on Programming 2001.

1 Nov 2001Yale28 Building a Custom Server browserserver script www socket back, forth, …

1 Nov 2001Yale29 Building a Custom Server The Operating System ServerCGI 1CGI 2CGI 3 cgi scripts are separate programs server inherits administration “thin” communication

1 Nov 2001Yale30 Building a Custom Server The Server CGI Script

1 Nov 2001Yale31 Building a Custom Server The Server CGI Script The server is an operating system. CGI scripts are applications, which are dynamically linked into the server.

1 Nov 2001Yale32 Building a Custom Server The Server CGI Script Server and script can exchange values -- “thick” communication.

1 Nov 2001Yale33 Building a Custom Server: How It Works (unit/sig () ; exports (import cgi^) ; imports (define title “My First Script”) `(html (title,title) (body (h1,title) “Hello World”))) (write-xml (xexpr->xml (invoke-unit/sig (load-unit (url->cgi url)) cgi^))) (define-signature cgi^ method ; (union ‘get ‘post) url ; URL headers ; (listof (cons Symbol String)) bindings ; (listof (cons Symbol String)) … )

1 Nov 2001Yale34 Building a Custom Server The Server CGI Script units are first-class values: load, cache, evaluate on demand.

1 Nov 2001Yale35 Building a Custom Server The Server CGI Script Retrieve from cache, link in -- yields expressive power.

1 Nov 2001Yale36 Building a Custom Server (let ([counter 0]) (unit/sig () ; exports (import cgi^) ; imports (set! counter (add1 counter)) `(html (body,(format “This page has been visited ~a times.”,counter))))) maintaining memory across cgi script invocations

1 Nov 2001Yale37 Building a Custom Server (let ([data … ] [lock … ]) `((add.,(unit/sig () (import cgi^) … ) (del.,(unit/sig () (import cgi^) (acquire lock) (set! data … ) (release lock))))) exchanging values between cgi scripts

1 Nov 2001Yale38 Building a Custom Server: How It Works (define-signature cgi^ … send/suspend ; (String -> XHTML) ->* Method Url Bindings send/finish ; XHTML -> Void … )

1 Nov 2001Yale39 Building a Custom Server (unit/sig () (import cgi^) (define (get-number which) (send/suspend (lambda (query-url) …))) `(html (title "The Multiply Page") (body "the result is ",(format "the result is: ~a" (* (get-number “first”) (get-number “second”)) ))) suspending cgi scripts via continuations define get-number in terms of send-suspend

1 Nov 2001Yale40 Building a Custom Server The Server CGI Script Server stores continuations for scripts. continuation send/suspend query-url

1 Nov 2001Yale41 Building a Custom Server: Positive Results implementing cgi scripts as first- class values adds lots of expressive power: –memo for values –exchanging values –suspending and resuming threads natural structure for interactive programs performance is first-rate: –static content: 80% of Apache –dynamic content: 4 to 5 times as fast –beats FastCGI by 20 to 40%

1 Nov 2001Yale42 Building a Custom Server: Problems Problem: server must provide OS- style services to CGI extensions: –protection –resource administration Solution: Flatt et al., “Programming Languages as Operating Systems”, ICFP 1999

1 Nov 2001Yale43 Building a Custom Server: Problems Problem: server provides storage for continuations; distributed and symbolic garbage collection Solution: time-out; imperfect Problem: must install a new server, use a specific language, ditch existing infrastructure Solution: coming soon …

1 Nov 2001Yale44 The Preprocessor Solution Graunke, Findler, Krishnamurthi, Felleisen: “How to Design and Generate CGI Programs”. Automated Software Eng. 2001

1 Nov 2001Yale45 Interaction from Preprocessing act as if your favorite language could grab continuations and send them to client-agent use continuation passing transformation to eliminate these non-features use closure conversion/lifting to eliminate higher-order functions now send continuation records to client

1 Nov 2001Yale46 Interaction from Preprocessing (define (get-number which) (printf "enter the ~a number " which) (flush-output) (read)) (format "the result is: ~a" (* (get-number "first") (get-number "second"))) use CPS to map it away! interaction functions are “continuation grabbers”

1 Nov 2001Yale47 Interaction from Preprocessing (get-number-cps "first" (lambda (first) (get-number-cps "second" (lambda (second) (format "the result is: ~a" (* first second)))))) higher-order functions: - not in all PLs - can’t send them to client close with free variables

1 Nov 2001Yale48 Interaction from Preprocessing (get-number-cps "first" [apply (lambda () (lambda (first) (get-number-cps "second" [apply (lambda (first) (lambda (second) (format "the result is: ~a" (* first second)))) (list first)]))) '()]) functions no longer depend on lexical scope lift and collect in vector

1 Nov 2001Yale49 Interaction from Preprocessing (define CLOSURES (vector ;; closure 1 (lambda () (lambda (first) (get-number-cps "second" [apply (vector-ref CLOSURES 1) (list first)]))) ;; closure 2 (lambda (first) (lambda (second) (format "the result is: ~a" (* first second)))))) (get-number-cps "first" [apply (vector-ref CLOSURES 0) '()]) we’re still using Scheme’s first-class closures use structs instead!

1 Nov 2001Yale50 Interaction from Preprocessing (define-struct closure (code env)) (define (apply-closure x the-arg) ((apply (vector-ref CLOSURES (closure-code x)) (closure-env x)) the-arg)) (define CLOSURES. (vector (lambda () … [make-closure 1 (list first)] … ) (lambda (first) … ))) (get-number-cps "first" [make-closure 0 '()]) closures (continuations) are now first-order data read can send them to client

1 Nov 2001Yale51 Interaction from Preprocessing: Dispatcher (cond [(null? bindings) (get-number-cps "first " (make-closure 0 '()) )] [(string=? (extract-bindings/single 'cont bindings) "0") (apply-closure (make-closure 0 (extract-bindings/single 'env bindings)) (extract-binding/single 'response bindings))] [(string=? (extract-bindings/single 'cont bindings) "1") … ]) send closure to client-agent receive closure from client and reconstruct

1 Nov 2001Yale52 Interaction from Preprocessing: Summary consider a form of “read” as a coroutine resumption point compile away with cps, closure passing, closure lifting add dispatching code

1 Nov 2001Yale53 Interaction from Preprocessing: Problem Problem: closure-continuations contain the values of free variables. That may include such information as the current account balance. Solution: encrypt the closure as it is send to the client. Decrypt when it comes back.

1 Nov 2001Yale54 Interaction from Preprocessing: Problem Problem: closure-continuations are large pieces of data. Solution: compress the closure as it is send to the client. Decompress when it comes back. Or, build VM that executes compressed byte codes.

1 Nov 2001Yale55 Interaction from Preprocessing: Problem Problem: Many PLs encourage stateful programming. Where does the state of mutable variables and mutable records go? Solution 1: use the store-passing transformation to make store explicit. Pass it along with continuation to client (as hidden field in web form).

1 Nov 2001Yale56 Interaction from Preprocessing: Problem Problem: Consumers can clone browser windows, copy pages, … and with it the store. Solution 2: register cells (store) and move it over as a cookie. Solution 2 (refined): add a sequence number to decide ordering of requests with same store. NOTE: Reintroduces server side storage.

1 Nov 2001Yale57 Interaction from Preprocessing: Problem Problem: The code that is executed is radically different from the code that the programmer keyed in. How does the programmer debug such code? Solution: In general, this is an open question. Solution: In Scheme, use call/cc and hook up the IDE to a Web browser.

1 Nov 2001Yale58 Summary

1 Nov 2001Yale59 Summary: Interactive CGI Scripts both customer server and preprocessors vastly increase expressive power for Web scripting languages both enable programmers to write scripts with a natural structure both enable programmers to write more complex scripts than current technology

1 Nov 2001Yale60 Summary: Interactive CGI Scripts the custom server easy-to-develop scripts “thin” connection to consumer fast works for special language only the preprocessor works in general “fat” connection to consumer slow difficult-to-develop scripts in general

1 Nov 2001Yale61 Summary: Future Work programming Web interactions is not a simple problem besides type for secure data communications, … … we also need a better understanding of the web’s control structure

1 Nov 2001Yale62 The End Robby Findler (Rice, NU) Paul Graunke (NU) Shriram Krishnamurthi (Brown) Steve van der Hoeven (Nice, France)