|
Slide 10.6: Calling a CGI script (Unix shell) Slide 10.8: Database accessing embedded in Java host language (JDBC) Home |
|
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.
| ~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
|