CS 330 Class 6 - PowerPoint PPT Presentation

1 / 10
About This Presentation
Title:

CS 330 Class 6

Description:

JavaScript event handlers can be attached to forms to verify user input matches ... Navigator (e.g. in sniff.txt) History (methods back, forward) ... – PowerPoint PPT presentation

Number of Views:101
Avg rating:3.0/5.0
Slides: 11
Provided by: cshil
Category:
Tags: class | sniff

less

Transcript and Presenter's Notes

Title: CS 330 Class 6


1
CS 330 Class 6
  • Programming plan for today
  • Form validation (Minimal Dynamic Pages Ch 4)
  • JavaScript objects (Flanagan Ch 13.1-13.12)
  • Model
  • Examples (status line, timeouts and intervals)
  • Start CGI

2
Form Validation
  • JavaScript event handlers can be attached to
    forms to verify user input matches what is
    expected.
  • How can we identify a valid zip? (valid1.htm)
  • Two parts (valid2.htm).
  • Verify each element as it is added via onchange
    event
  • Verify the entire form as it is sent to the
    server via onsubmit event
  • Larger example, guest2.htm
  • What constitutes a valid name? phone? email?
    password?
  • Exercise augment guest2.htm to cover other
    fields.

3
JavaScript Objects
  • Window the top-level object
  • Properties and methods p. 199
  • More detail beginning on p. 653
  • Many properties/methods omit the window.
  • window.document.lastModfied
    document.lastModfied
  • Document what is written in the window.
  • properties bgColor, lastModified
  • Method write
  • Location (method replace (frogs)
  • Navigator (e.g. in sniff.txt)
  • History (methods back, forward)
  • See Part IV for a complete reference

4
JavaScript Objects
  • Status line (13.3)
  • Window has a status property that controls the
    status line msg.
  • Example mouse over a hypertext link displays
    the URL
  • User controlled
  • window.status message (or status message)
  • Example status.htm
  • Timeouts and intervals (13.4)
  • Code timed to execute at a specific time or
    intervals.
  • Often it is initiated when the page is loaded via
    an attribute in ltbodygt or triggered by another
    event and executed at subsequent intervals.
  • Example 13-2, p 205 (timeout.htm).

5
Introduction to CGI
  • Common gateway interface
  • CGI allows interactions among client browser, web
    server, and traditional applications. E.g.
  • Processing forms
  • Gateways (to services not immediately available
    to the client, e.g. a database)
  • Virtual documents (tailored to the user input,
    e.g. Google results)
  • CGI programs are run on the server
  • Results are often sent back in a client page

6
Client/Server Communication
Client (1)
Server (3)
(2)
client program
server program
(4)
(5)
Steps (1) Client program makes
connection to server program (2) Client sends
HTTP request message (3) Server processes
HTTP request message (4) Server sends HTTP
response message (5) Server closes the
connection
7
CGI Communication
Server Machine
(1)
Client
Server SW
(5)
(4)
(2)
Other servers
CGI Script (3)
Other programs
(1) Server SW decodes client HTTP request (2)
Server SW sets variables and executes CGI
script (3) CGI script runs (4) Script returns
output with CGI headers to server SW (5) Server
translates output and headers into HTTP response
to client
8
Languages for CGI Scripts
  • UNIX shell commands
  • C, C
  • Perl (practical extraction and report language)
  • Visual Basic
  • Cold Fusion, ASP, PHP
  • Why Perl?
  • Portable
  • Powerful string manipulation operations
  • C-like syntax
  • Why not?
  • Lower-level than Cold Fusion, ASP, PHP

9
CGI With No Parameters
  • hello.htm invokes script hello.cgi via
  • ltagt ref"http/../scripts/hello.cgi"gt
    Hello Worldlt/agt
  • This generates HTTP header GET
    ../scripts/hello.cgi
  • hello.cgi
  • !/usr/bin/perl
    //The first line indicates the language
  • print "Content-type text/html\n\n"
    //Part of the returned HTTP header
  • print "lthtmlgt\n"
  • print "ltheadgt\n"
  • print "lttitlegtHello Worldlt/titlegt"
  • print "lt/headgt\n"
  • print "ltbodygt\n"
  • print "Hello World\n"
  • print "lt/bodygt\n"
  • print "lt/htmlgt\n"

10
  • Where do the CGI Scripts reside?
  • Any directory in a file with a .cgi extension
  • Our convention in subdirectory
    public_html/scripts (hello1.cgi)
  • /cgi-bin/ if allowed by the system administrator
    (hello2.cgi) via
  • ScriptAlias /cgi-bin/ /etc/httpd/cgi-bin in
    srm.conf
  • ExecCGI enabled for /home/ and
    /etc/httpd/cgi-bin in access.conf
  • Logistics
  • Your programs should
  • have a .cgi extension
  • have execute permission (chmod ax .cgi)
  • reside in your scripts directory
  • return an HTML document
  • Edit on local computer and ftp or telnet and
    copy to aurora via
  • cat gt progname.cgi (paste) Ctrl/C
  • Check syntax in telnet
  • perl hello.cgi (try this)
  • this displays what is normally sent back to the
    server
Write a Comment
User Comments (0)
About PowerShow.com