chapter nine n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Chapter Nine PowerPoint Presentation
Download Presentation
Chapter Nine

Loading in 2 Seconds...

play fullscreen
1 / 48

Chapter Nine - PowerPoint PPT Presentation


  • 47 Views
  • Uploaded on

Chapter Nine. Compiled Web Server Programs. 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

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Chapter Nine' - havyn


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
chapter nine

ChapterNine

Compiled Web

Server Programs

chapter objectives
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
chapter objectives1
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
common gateway interface
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
common gateway interface1
Common Gateway Interface

Figure 9-1: CGI processing architecture

processing inputs and outputs in cgi programs
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
processing inputs and outputs in cgi programs1
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
writing a cgi program using visual basic
Writing a CGI Program Using Visual Basic
  • Visual Basic can be used to create CGI programs
    • VB doesn’t directly support reading from STDIN and STDOUT
    • To create CGI programs using VB, use a VB standard module named cgi.bas

Module contains declarations of Windows API functions that enable VB to read from STDIN and write to STDOUT

writing a cgi program using visual basic1
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
debugging cgi programs in visual basic
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
debugging cgi programs in visual basic1
Debugging CGI Programs in Visual Basic

Figure 9-10: String concatenation error

debugging cgi programs in visual basic2
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
debugging cgi programs in visual basic3
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
debugging cgi programs in visual basic4
Debugging CGI Programs in Visual Basic

FIGURE 9-13: Code window with execution paused at breakpoint

debugging cgi programs in visual basic5
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
debugging cgi programs in visual basic6
Debugging CGI Programs in Visual Basic

Figure 9-14: Query to display variable value in the Immediate window

creating hyperlinks to pass parameter values in cgi programs
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 (&)
creating hyperlinks to pass parameter values in cgi programs1
Creating Hyperlinks to Pass Parameter Values in CGI Programs

Figure 9-16: Code to create hyperlinks with URL parameter values

creating hyperlinks to pass parameter values in cgi programs2
Creating Hyperlinks to Pass Parameter Values in CGI Programs

Figure 9-17: Item ID hyperlink URL parameter value

sharing data values with other cgi programs
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
sharing data values with other cgi programs1
Sharing Data Values with Other CGI Programs
  • Cookie
    • Data file that is written on the user’s 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
advantages and disadvantages of using cgi programs
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
advantages and disadvantages of using cgi programs1
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
advantages and disadvantages of using cgi programs2
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 server’s 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
using activex dlls for server side web processing
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
using activex dlls for server side web processing1
Using ActiveX DLLs for Server-side Web Processing
  • ActiveX DLL
    • Code module that is stored on the Web server
    • Runs in the Web server’s memory space
    • Can be used only with Microsoft Web servers
using activex dlls for server side web processing2
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
differences between activex dlls and cgi programs
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
differences between activex dlls and cgi programs1
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
creating an activex dll using visual basic
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
registry changes made when an activex dll is compiled
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
registry changes made when an activex dll is compiled1
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
registry changes made when an activex dll is compiled3
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
retrieving database data in an activex dll
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
retrieving database data in an activex dll1
Retrieving Database Data in an ActiveX DLL
  • When an ActiveX DLL is called from another program, the DLL remains in the Web server’s 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
passing form input parameters to an activex dll
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 DLL’s procedure as VB procedure parameters
passing form input parameters to an activex dll1
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 user’s browser
passing form input parameters to an activex dll2
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
passing form input parameters to an activex dll3
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
chapter summary
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
chapter summary1
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
chapter summary2
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