100 likes | 127 Views
Lisp CGI Programming for the Web. Web servers can invoke Lisp to “intelligently” create web pages on the fly. We will use the host cubist.cs.washington.edu to explore this form of programming. Common Gateway Interface.
E N D
Lisp CGI Programming for the Web Web servers can invoke Lisp to “intelligently” create web pages on the fly. We will use the host cubist.cs.washington.edu to explore this form of programming. CSE 341, S. Tanimoto Lisp CGI -
Common Gateway Interface CGI: A standard method whereby a web server can invoke another program to handle a query. HTTP: HyperText Transfer Protocol -- a standard for information requests and responses over the Internet. CSE 341, S. Tanimoto Lisp CGI -
GET and POST GET. An HTTP request method in which parameters to a query are encoded as part of the URL and made available to a CGI program via environment variables. http://www.lispfun.org/cgi-bin/weather.lsp?day=yesterday+time=night POST. An HTTP request method in which parameters to a query are transmitted separately and passed to the program via the standard input stream. http://www.lispfun.org/cgi-bin/weather.lsp CSE 341, S. Tanimoto Lisp CGI -
A Simple CGI Program #! /usr/local/bin/gcl.exe -f (format t ”Content-type: text/html~%~%”) (format t ”<html><head><title>Lispy</title></head>”) (format t ”<body><h1>Hello Web!</body></html>”) (bye) This assumes the server is a Unix host, and that the Lisp system is Gnu Common Lisp. CSE 341, S. Tanimoto Lisp CGI -
(Brief Aside) Unix Commands List the contents of the directory with longer descriptions: cubist$ls -l Descend one level in the directory hierarchy: cubist$cd www Ascend one level in the directory hierarchy: cubist$cd .. Rename a file: cubist$mv test.lsp solution.lsp Move a file to a child directory: cubist$mv solution.lsp www/ CSE 341, S. Tanimoto Lisp CGI -
More Unix Commands Remove (delete) a file: cubist$rm test1.lsp Create a new subdirectory: cubist$mkdir new-stuff Remove a subdirectory: cubist$rmdir old-stuff Execute a Lisp program from the command line: cubist$gcl solution.lsp cubist$./solution.lsp provided the first line of solution.lsp is... #! /usr/local/gcl -f CSE 341, S. Tanimoto Lisp CGI -
More Unix Commands (cont.) chmod stands for “change mode”. Remove permissions to execute a file: cubist$chmod -x test1.lsp Give group permission to execute: cubist$chmod g+x test1.lsp Give read permission to all users: cubist$chmod +r test1.lsp Take away write permission from others: cubist$chmod o-w test1.lsp CSE 341, S. Tanimoto Lisp CGI -
CGI and Sessions HTTP is “stateless” Meaningful interactions often require “sessions” Session continuity is a challenge. 3 separate mechanisms support solutions: 1. Passing session ID parameters between client and server with each transfer. 2. Using “cookies” on the client to identify a user or a session. 3. Storing a session file on the server between requests from a user. CSE 341, S. Tanimoto Lisp CGI -
Other Details of CGI Programming Parameter fetching for GET and POST methods. Printing an appropriate HTTP header. Maintaining adequate levels of security: filtering user input and never executing it directly. Avoiding server time-outs. CSE 341, S. Tanimoto Lisp CGI -
Code Example The KNOCK.LSP program carries on a dialog with the user over the web, telling “knock-knock” jokes. It illustrates three methods for saving session state: parameter passing, client-side cookies, and server-side session files. The code is available at: http://cubist.cs.washington.edu/~tanimoto/knock.txt CSE 341, S. Tanimoto Lisp CGI -