Chapter Nine - PowerPoint PPT Presentation

1 / 47
About This Presentation
Title:

Chapter Nine

Description:

... Common Gateway Interface (CGI) ... Common Gateway Interface. Figure 9-1: CGI processing ... Common Gateway Interface (CGI) is a protocol that specifies how ... – PowerPoint PPT presentation

Number of Views:88
Avg rating:3.0/5.0
Slides: 48
Provided by: Pau17
Category:
Tags: chapter | gateway | nine

less

Transcript and Presenter's Notes

Title: Chapter Nine


1
ChapterNine
  • Compiled Web
  • Server Programs

2
Chapter Objectives
  • Learn about Common Gateway Interface (CGI)
  • Create CGI programs that generate dynamic Web
    pages using Visual Basic, and learn the
    advantages and disadvantages of using CGI
    programs to create dynamic Web pages
  • Pass parameter values among CGI programs

3
Chapter Objectives
  • Learn about ActiveX dynamic-link libraries (DLLs)
    and their advantages and disadvantages
  • Create an ActiveX DLL that generates a Web page
  • Call an ActiveX DLL from an Active Server Page

4
Common Gateway Interface
  • Common Gateway Interface (CGI)
  • Protocol that specifies how Web servers and
    compiled programs for processing user inputs that
    run on the Web server communicate with each other
  • Developed as a protocol for programs that process
    data entered into HTML forms and use these inputs
    to generate dynamic Web pages

5
Common Gateway Interface
Figure 9-1 CGI processing architecture
6
Processing Inputs and Outputs in CGI Programs
  • In the early days of mainframe computing
  • Standard input (STDIN) referred to a memory
    location where user input from the keyboard was
    stored
  • Standard output (STDOUT) referred to a memory
    location where output to be displayed on the
    monitor was stored

7
Processing Inputs and Outputs in CGI Programs
  • The terms STDIN and STDOUT are no longer used to
    reference keyboard input and monitor output
  • STDIN and STDOUT now define a standard way of
    communicating the locations of inputs and outputs
    between different programs

8
Writing a CGI Program Using Visual Basic
  • Visual Basic can be used to create CGI programs
  • VB doesnt directly support reading from STDIN
    and STDOUT
  • To create CGI programs using VB, use a VB
    standard module named cgi.bas

9
Writing a CGI Program Using Visual Basic
  • The cgi.bas module contains declarations of
    Windows API (Application Programming Interface)
    functions that enable Visual Basic to read from
    STDIN and write to STDOUT
  • Windows API is a set of code libraries that
    developers can incorporate within Windows
    applications written in a variety of languages,
    to create standard Windows program components

10
Using the cgi.bas Standard Module
Table 9-1 cgi.bas procedures and functions
11
Using the cgi.bas Standard Module
  • The InitializeCGI procedure must be called before
    using the other procedures in cgi.bas
  • The InitializeCGI procedure can be called only
    once at the beginning of your program
  • The stdOut function receives a string containing
    the program outputs as an input variable, and
    writes these outputs to STDOUT

12
Using the cgi.bas Standard Module
  • The DisplayAll procedure is used in the first CGI
    program that you will write to display the names
    and values of all the form inputs and environment
    variables
  • The GetInput function receives the name of an
    HTML form variable as an input parameter, and
    retrieves the value of the variable from STDIN

13
Debugging CGI Programs in Visual Basic
  • The main source of errors in CGI programs
    developed in Visual Basic is concatenation
    errors, where the SQL or HTML commands are not
    correctly formed as text strings
  • Commands with incorrectly formed text strings are
    usually easy to spot
  • The VB editor displays
  • Lines with syntax errors in red
  • A message box describing the error when you enter
    the code

14
Debugging CGI Programs in Visual Basic
Figure 9-10 String concatenation error
15
Debugging CGI Programs in Visual Basic
  • After eliminating the red errors, there still
    might be errors from text strings where the
    syntax is correct, but the content is not correct
  • This usually happens when you concatenate
    variable values with text strings to create SQL
    queries

16
Debugging CGI Programs in Visual Basic
  • Breakpoint
  • A place in a program where execution is paused
    while the program is running, allowing the
    developer to examine variable values
  • When program execution is paused at a breakpoint,
    place the mouse pointer on any reference variable
    in the program code, and the current value of the
    variable will be displayed in the ToolTip window

17
Debugging CGI Programs in Visual Basic
FIGURE 9-13 Code window with execution paused at
breakpoint
18
Debugging CGI Programs in Visual Basic
  • Placing the mouse pointer on variable values to
    determine their current values works well for
    variable values that are fairly short
  • When a query string is very long, some of the
    text might not appear in the ToolTip window
  • Immediate window
  • Testing area that is displayed when an execution
    is paused while a VB program is running in the VB
    Integrated Development Environment

19
Debugging CGI Programs in Visual Basic
Figure 9-14 Query to display variable value in
the Immediate window
20
Creating Hyperlinks to Pass Parameter Values in
CGI Programs
  • The hyperlink lists the name of the CGI program,
    followed by a question mark and the parameter
    list variable name/value pairs
  • Each individual variable name/value pair is
    separated from the next by an ampersand ()

21
Creating Hyperlinks to Pass Parameter Values in
CGI Programs
Figure 9-16 Code to create hyperlinks with URL
parameter values
22
Creating Hyperlinks to Pass Parameter Values in
CGI Programs
Figure 9-17 Item ID hyperlink URL parameter value
23
Sharing Data Values with Other CGI Programs
  • CGI programs, like Active Server Pages, can pass
    data values as URL parameters, as form
    parameters, or as cookies
  • URL parameters are passed to a CGI program within
    a form ACTION tag by forming the ACTION parameter
    using the name of the CGI executable file and a
    question mark, and then listing the URL parameter
    variable name/value pairs, separated by ampersands

24
Sharing Data Values with Other CGI Programs
  • Form parameter
  • Passed to the Web server when an HTML form is
    submitted to the Web server by the user
  • Form parameters are the names and associated
    values of form controls are written to STDIN when
    a form is submitted to the Web server

25
Sharing Data Values with Other CGI Programs
  • Cookie
  • Data file that is written on the users
    workstation by a program within a Web page
  • Available to any Web page in an application,
    regardless of the order in which the Web page is
    selected and viewed

26
Advantages and Disadvantages of Using CGI Programs
  • CGI programs can be written in any programming
    language that allows users to write values
    directly to STDIN and STDOUT on a Web server
  • A CGI program can be used with most Web servers
    and operating systems
  • In contrast, Active Server Pages run only on a
    Microsoft Web server

27
Advantages and Disadvantages of Using CGI Programs
  • CGI programs are compiled programs
  • The program source code is converted into machine
    language when you compile the program
  • In contrast, script commands must be converted
    into machine language each time the script is run
  • For this reason, compiled programs execute (run)
    much faster than scripts

28
Advantages and Disadvantages of Using CGI Programs
  • The drawback of CGI programs is that they do not
    use Web server resources efficiently
  • On a busy Web site using CGI programs, all of the
    Web servers main memory could be consumed trying
    to service multiple submissions of the same HTML
    form, and the Web server would be very slow in
    sending responses back to users
  • To solve this problem, vendors are developing
    products to allow a single CGI program to service
    multiple submissions of the same form

29
Using ActiveX DLLs for Server-side Web Processing
  • A dynamic link library (DLL) is not a stand-alone
    program, but it contains code that can be linked
    to, or used by, many different programs
  • The code modules in a DLL are called libraries
    because their code can be checked out and used
    by many different programs
  • A DLL is somewhat different from a conventional
    library in that the code from a specific DLL can
    be used simultaneously by many different programs

30
Using ActiveX DLLs for Server-side Web Processing
  • ActiveX DLL
  • Code module that is stored on the Web server
  • Runs in the Web servers memory space
  • Can be used only with Microsoft Web servers

31
Using ActiveX DLLs for Server-side Web Processing
  • ActiveX DLLs have a significant advantage over
    CGI programs
  • A single copy of an ActiveX DLL can service an
    unlimited number of user requests without
    starting additional copies of the program

32
Differences Between ActiveX DLLs and CGI Programs
  • Unlike a CGI program, an ActiveX DLL
  • Is not a stand-alone program
  • Comprises one or more procedures that must be
    called from another program
  • Must be entered into the Registry of the Web
    server where it will be used, so that other
    programs will be able to call the procedures
    within the DLL

33
Differences Between ActiveX DLLs and CGI Programs
  • When an ActiveX DLL is called from an ASP, you
    must explicitly add the code to send the form
    inputs as parameters from the ASP to the DLL in
    the ASP command that calls the ActiveX DLL
    procedure
  • When an ActiveX DLL is called from an ASP, it
    returns outputs to the calling ASP script either
    as a value returned by a function, or by changing
    the values of variables that were passed to the
    ActiveX DLL as input parameters from the calling
    program

34
Creating an ActiveX DLL Using Visual Basic
  • A VB ActiveX DLL consists of a class module that
    contains multiple functions or procedures that
    can be called by programs that link to the DLL
  • Class
  • Template from which an object is created

35
Registry Changes Made When an ActiveX DLL is
Compiled
  • Normally, Registry entries are made by programs
    when they are installed or modified
  • Registry stores information such as
  • The location of program files
  • User preferences such as the toolbars that are
    displayed in a program

36
Registry Changes Made When an ActiveX DLL is
Compiled
  • To view Registry entries on a Windows95,
    Windows98, Windows NT, or Windows 2000
    workstation, use a utility named REGEDIT
  • REGEDIT enables users to view and change Registry
    entries
  • Normally, you never need to modify the Registry
    manually

37
Registry Changes Made When an ActiveX DLL is
Compiled
Figure 9-41 Registry Editor
38
Registry Changes Made When an ActiveX DLL is
Compiled
  • Key
  • Parent item that can be a folder, or variable
    that has an associated value
  • Value
  • Text string that is associated with a key
    variable
  • A key folder can have a default value
  • Value that is associated with the key folder if a
    query does not specify the name of a key within
    the key folder

39
Retrieving Database Data in an ActiveX DLL
  • You can an ActiveX DLL to perform operations that
    you cannot perform in an ASP
  • You can also link an ActiveX DLL to an ASP to
    perform database operations
  • While database operations can be performed
    directly within the ASP script code, you can
    enhance the execution speed of the ASP if you
    perform some operations using a DLL, since the
    DLL is compiled prior to execution

40
Retrieving Database Data in an ActiveX DLL
  • When an ActiveX DLL is called from another
    program, the DLL remains in the Web servers
    memory until the Web server is rebooted
  • You cannot recompile the DLL, because the DLL is
    loaded into memory, and is marked as being in use
    by the operating system
  • To recompile a DLL that has been called by a
    program, you must reboot your computer and
    recompile the DLL

41
Passing Form Input Parameters to an ActiveX DLL
  • ISAPI enables you to create DLLs that can be
    called directly by the Web server
  • When you call an ActiveX DLL from an ASP, the
    ActiveX DLL has no built-in way to directly read
    form inputs
  • The alternative is to use the Request.Querystring
    property in the ASP to retrieve the form inputs
    in the ASP, and then send the parameters to the
    ActiveX DLLs procedure as VB procedure parameters

42
Passing Form Input Parameters to an ActiveX DLL
  • When creating ActiveX DLLs in VB to generate
    dynamic Web pages
  • Create functions within the ActiveX DLL that
    return
  • A text string containing all HTML commands
  • Formatted texts
  • Retrieved data values to be displayed by the
    users browser

43
Passing Form Input Parameters to an ActiveX DLL
  • When creating ActiveX DLLs in VB to generate
    dynamic Web pages (cont.)
  • Create an Active Server Page to
  • Call functions within an ActiveX DLL
  • Pass input parameter values to the DLL functions
  • Display the function return value, which is a
    text string that represents a formatted Web page

44
Passing Form Input Parameters to an ActiveX DLL
  • When creating ActiveX DLLs in VB to generate
    dynamic Web pages (cont.)
  • To retrieve database data in an ActiveX DLL
  • Create an ADODB connection object to reference a
    database
  • Use the recordset Executive method to manipulate
    data using SQL commands

45
Chapter Summary
  • Common Gateway Interface (CGI) is a protocol that
    specifies how a Web server communicates with
    programs running on the Web server
  • CGI is usually used to process data that are
    entered into HTML forms using STDIN and STDOUT
  • STDIN and STDOUT are memory locations on a
    computer that define a standard way for different
    programs to share the values of inputs and outputs

46
Chapter Summary
  • A CGI program can be written in any language
    that can be read from STDN, write data to STDOUT,
    and read environment variables
  • CGI programs can use URL parameters, form
    parameters, or cookies to share data values with
    other CGI programs
  • CGI programs can run on most Web servers, and on
    a variety of operating systems

47
Chapter Summary
  • The main drawback of CGI programs is that they do
    not use Web server resources efficiently
  • Dynamic-link libraries (DLLs) are collections of
    compiled code modules that are called from other
    programs
  • ActiveX DLLs have a significant advantage over
    CGI programs, since a single copy of an ActiveX
    DLL can service an unlimited number of user
    requests without starting additional copies of
    the program
Write a Comment
User Comments (0)
About PowerShow.com