CS 330 Class 10 - PowerPoint PPT Presentation

1 / 12
About This Presentation
Title:

CS 330 Class 10

Description:

read and display data from the pizza topping survey #retrieve the current survey information ... Be able to add a new topping. Summary of CGI on UNIX ... – PowerPoint PPT presentation

Number of Views:22
Avg rating:3.0/5.0
Slides: 13
Provided by: arnoldsh
Category:
Tags: class | topping

less

Transcript and Presenter's Notes

Title: CS 330 Class 10


1
CS 330 Class 10
  • One more CGI examples with files
  • pizza.htm
  • CGI on UNIX and Windows

2
Conducting as Survey via a Form
  • pizza.htm viewers vote for favorite topping
  • pizza.cgi saves the vote
  • results.cgi display results
  • Data is stored in ../data/pizza.dat in the form
  • CheesePepperoniAnchoviesMushroomsBlackOliv
    es
  • 10423292121
  • Request to vote is of the form
    pizza.cgi?toppingCheese

3
  • pizza.cgi
  • !/usr/bin/perl
  • parse the form data
  • _at_pairs split (//,ENV'QUERY_STRING')
  • foreach pair (_at_pairs)
  • (field_name, value) split(//,pair)
  • formfield_namevalue
  • user_selection form'topping'
  • retrieve the current survey information
  • if (open SURVEY, "lt../data/pizza.dat")
  • for (i0 ilt2 i)
  • linei ltSURVEYgt
  • chop(linei)
  • close SURVEY
  • else

4
  • unpack the stored survey information
  • _at_options split("", line0)
  • _at_data split("", line1)
  • find and increment the selected item
  • for (i0 iltoptions i)
  • if (optionsi eq user_selection)
  • item_noi
  • last
  • dataitem_no
  • store the updated survey information
  • line1 join ('', _at_data)
  • if(open SURVEY, "gt../data/pizza.dat")
  • print SURVEY line0, "\n"
  • print SURVEY line1, "\n"

5
  • presults.cgi
  • !/usr/bin/perl
  • read and display data from the pizza topping
    survey
  • retrieve the current survey information
  • if (open SURVEY, "lt../data/pizza.dat")
  • for (i0 ilt2 i)
  • linei ltSURVEYgt
  • chop(linei)
  • close SURVEY
  • else
  • error handling code
  • unpack the stored survey information
  • _at_options split("", line0)
  • _at_data split("", line1)

6
  • print the results
  • print "Content-type text/html\n\n"
  • print "lthtmlgt\n"
  • print "ltheadgtlttitlegtPizza Surveylt/titlegtlt/headgt\n"
  • print "ltbodygt\n"
  • print "lttablegt\n"
  • print "ltbgtlttrgtltthgtTopping lt/thgtltthgtVoteslt/thgtlt/trgt
    lt/bgt\n"
  • for (i0 iltoptions i)
  • print "lttrgtlttdgtoptionsilt/tdgtlttdgtdatailt/
    tdgtlt/trgt\n"
  • print "lt/tablegt\n"
  • print "lt/bodygtlt/htmlgt\n"
  • Comment
  • options is the size of the array
  • Enhancements?
  • Detect spurious votes
  • Be able to add a new topping

7
Summary of CGI on UNIX
  • HTTP the language that web clients and servers
    use to communicate with each other
  • CGI the part of a web server that can
    communicate with other programs that are running
    on the server
  • Our approach to CGI so far
  • UNIX platform with scripts written in Perl
  • Scripts use information from
  • HTTP environment variables
  • files on the server
  • Output to
  • print statements that create an HTML document
  • files on the server

8
Higher Level Approaches to CGI
  • Cold Fusion
  • Owned by Macromedia
  • A giant leap in usability from Perl
  • Interfaces with most commercial databases
  • ASP (Active Server Pages)
  • Microsofts answer to CF
  • Many companies migrated to it from CF
  • Now being supplanted by ASP.NET
  • PHP
  • Free, interfaces with MySQL (free) and other
    commercial dbs
  • Stable but evolving.
  • All are multi-platform, but ASP is best-supported
    on IIS.
  • Cold Fusion tags, ASP code, or PHP code are
    embedded in HTML page
  • and preprocessed before resulting page is sent to
    the client.

9
Client/Server Communication
10
Cold Fusion Processing
  • A user requests a page in a Cold Fusion
    application by submitting a form or clicking on a
    hyperlink.
  • The web server passes the data submitted by the
    client and the requested page to the Cold Fusion
    application server.
  • Cold Fusion reads the data from the client and
    processes the CFML tags in the page.
  • Based on the CFML, the Cold Fusion Application
    Server executes the application logic and
    interacts with a wide range of server
    technologies.
  • Cold Fusion dynamically generates an HTML page
    and returns it to the Web server.
  • The web server returns the page to the users
    browser.

11
Cold Fusion Markup Language (CFML)
  • Tags embedded in HTML
  • ltCFQUERYgt lt/CFQUERYgt is used to submit any SQL
    statements to an OBDC data source.
  • ltCFOUTPUTgt lt/CFOUTPUTgt to mark code that Cold
    Fusion should process prior to submitting it to
    the web server for sending to a browser
  • Links to data sources are set up with an ODBC
  • driver and referred to in queries.

12
  • lt!--- Database query ---gt
  • ltCFQUERY NAME"Animal" DATASOURCE"DW Database"gt
  • SELECT FROM Animal
  • lt/CFQUERYgt
  • ltHTMLgtltHEADgtltTITLEgtAnimals at the DeWitt Animal
    Hospitallt/TITLEgtlt/HEADgt
  • ltBODYgtltCENTERgtltH1gtThe DeWitt Animal Hospitallt/H1gt
  • ltPgtltIgtThis is a Cold Fusion query of the DW
    Database for the DeWitt Animal Hospital. The
    query selects all of the Animal table and outputs
    animal name and animal breed in a table.lt/Igtlt/Pgt
  • ltTABLE BORDER5gt
  • ltTRgtltTH COLSPAN2gtltH2gtAnimal Name and
    Breedlt/H2gtlt/THgtlt/TRgt
  • lt!--- Output of database query ---gt
  • ltCFOUTPUT QUERY"Animal"gt
  • ltTRgt
  • ltTDgtAnimalNamelt/TDgt
  • ltTDgtBreedlt/TDgt
  • lt/CFOUTPUTgt
  • lt/TABLEgt
  • lt/CENTERgtlt/BODYgtlt/HTMLgt
Write a Comment
User Comments (0)
About PowerShow.com