Slide 10.6: Calling a CGI script (Unix shell)
Slide 10.8: Database accessing embedded in Java host language (JDBC)
Home

How to Construct the Exercise II (Cont.)

  1. Calling a CGI (Common Gateway Interface) Script (Perl) JDBC instead of Perl programming is the focus of this course. So the CGI Perl script ListTitles.pl is minimal and it performs the following two tasks:

    • The first part is to retrieve user's data from the Web and put it into variables by using the param function. For example, after executing the following commands:
       use CGI; 
       $query = new CGI;
       $name  = $query->param( 'name' );
      the variable $name contains “Michael” from the web input:
       <input type="text" size="32" name="name" value="Michael">
      For details, check Perl CGI web-related module.

    • The second part does the actual processing by calling programs of embedded-SQL languages such as JDBC or 3G languages like C.

    ~wenchen/public_html/cgi-bin/351/week10/ListTitles.pl
    #!/usr/bin/perl
    print "Content-type: text/html\n\n";
    use CGI; 
    $query = new CGI;
    
    # Retrieve web argument values.
    $act = $query->param( 'act'  );
    
    print <<EndofHTML;
    <html>
     <body>
    EndofHTML
    
    if ( $act eq "List the titles" ) {
      $name = $query->param( 'name' );
      # Remove leading and trailing spacing.
      $name =~ s/^\s*(\S*)\s*$/$1/;
      # For security, remove some Unix metacharacters.
      $name =~ s/;|>|>>|<|\*|\?|\&|\|//g;
      system ( "/usr/bin/java  ListTitles '$name'" ); 
    }
    elsif ( $act eq "Help" ) {
      system( "/bin/cat  Help.html" );
    }
    else {
      print( "No such option: <em>$act</em>" );
    }
    
    print <<EndofHTML;
     </body>
    </html>
    EndofHTML