Drop-Down Lists and Hyperlinks
This slide shows how to send the user input including a drop-down list to a server for processing.
If you select some options below and click the “Submit” button, the browser will call the following scripts:
10.html ⇒ Select.cgi ⇒ Select.pl ⇒ Select.java ⇒ HTML ⇒ Hyperlink.pl
and list the descriptions hyperlinked with the corresponding cities based on the selected brands.
02 | < select name = "brand" multiple size = "3" > |
03 | < option value = "MKF Studios" /> MKF Studios |
04 | < option value = "Wolf" /> Wolf |
05 | < option value = "Parabuster Inc." /> Parabuster Inc. |
06 | < option value = "Big Studios" /> Big Studios |
08 | < input type = "submit" name = "act" value = "Submit" /> |
09 | < input type = "submit" name = "act" value = "HTML source" /> |
10 | < input type = "submit" name = "act" value = "CGI source" /> |
11 | < input type = "submit" name = "act" value = "Perl source" /> |
12 | < input type = "submit" name = "act" value = "Java source" /> |
13 | < input type = "submit" name = "act" value = "Hyperlink source" /> |
14 | < input type = "submit" name = "act" value = "Help" /> |
15 | < input type = "reset" value = "Reset" /> |
|
|
|
The following code,
Select.cgi
is used to set the web environment for the Oracle database:
~/public_html/cgi-bin/jdbc/Select.cgi
|
3 | CLASSPATH=.: /usr/lib/oracle/23/client64 |
4 | CLASSPATH=$CLASSPATH: /usr/lib/oracle/23/client64/lib/ojdbc8 .jar |
5 | CLASSPATH=$CLASSPATH: /usr/lib/oracle/23/client64/lib/ottclasses .zip |
|
The following Perl script is mainly used to process the web inputs including the drop-down list.
~/public_html/cgi-bin/jdbc/Select.pl
|
04 | $act = $query ->param( 'act' ); |
06 | if ( $act eq "Submit" ) { |
08 | print ( "Content-type: text/html\n\n" ); |
16 | <body text= "#000000" vLink= "#3366CC" link = "#3366CC" bgColor= "#ffffff" |
19 | <font size= "+0" color= "#3366CC" > |
23 | $cmd = "/usr/bin/java -Djava.security.egd=file:/dev/./urandom Select " ; |
24 | my @brands = $query ->param( 'brand' ); |
25 | foreach my $brand ( @brands ) { $cmd .= "'" . $brand . "' " ; } |
26 | print ( $cmd ); system ( $cmd ); |
35 | elsif ( $act eq "HTML source" ) { |
37 | print ( "Content-type: text/plain\n\n" ); |
38 | $cmd = "/usr/bin/lynx -dump -source " . $ENV {HTTP_REFERER}; |
39 | $cmd .= "; echo \n\n\n\n" ; |
42 | elsif ( $act eq "CGI source" ) { |
43 | print ( "Content-type: text/plain\n\n" ); |
44 | system ( "/bin/cat Select.cgi; echo \n\n\n\n" ); |
46 | elsif ( $act eq "Perl source" ) { |
47 | print ( "Content-type: text/plain\n\n" ); |
48 | system ( "/bin/cat Select.pl; echo \n\n\n\n" ); |
50 | elsif ( $act eq "Java source" ) { |
51 | print ( "Content-type: text/plain\n\n" ); |
52 | system ( "/bin/cat Select.java; echo \n\n\n\n" ); |
54 | elsif ( $act eq "Hyperlink source" ) { |
55 | print ( "Content-type: text/plain\n\n" ); |
56 | system ( "/bin/cat Hyperlink.pl; echo \n\n\n\n" ); |
58 | elsif ( $act eq "Help" ) { |
59 | print ( "Content-type: text/html\n\n" ); |
60 | system ( "/bin/cat Help.html" ); |
63 | print ( "Content-type: text/html\n\n" ); |
64 | print ( "No such option: <em>$act</em>" ); |
|
The following JDBC script accesses the database and retrieves the descriptions and cities.
~/public_html/cgi-bin/jdbc/Select.java
|
01 | /******************************************************************* |
03 | This program shows how to list the cities and |
04 | descriptions in the stores and productions tables |
07 | To use this program, you need to create the following |
08 | three tables by using the following commands: |
10 | SQL> CREATE TABLE stores ( |
11 | 2 store_key INTEGER PRIMARY KEY, |
12 | 3 city VARCHAR(32) NOT NULL, |
13 | 4 region VARCHAR(16) NOT NULL ); |
15 | SQL> CREATE TABLE products ( |
16 | 2 product_key INTEGER PRIMARY KEY, |
17 | 3 description VARCHAR(32) NOT NULL, |
18 | 4 brand VARCHAR(32) NOT NULL ); |
20 | SQL> CREATE TABLE sales_fact ( |
22 | 3 product_key INTEGER, |
23 | 4 sales NUMBER(5,2) NOT NULL, |
24 | 5 cost NUMBER(5,2) NOT NULL, |
25 | 6 profit NUMBER(5,2) NOT NULL, |
26 | 7 PRIMARY KEY ( store_key, product_key ), |
27 | 8 FOREIGN KEY ( store_key ) REFERENCES stores( store_key ) ON DELETE CASCADE, |
28 | 9 FOREIGN KEY ( product_key ) REFERENCES products( product_key ) ON DELETE CASCADE ); |
30 | *******************************************************************/ |
36 | import oracle.jdbc.pool.OracleDataSource; |
39 | public static void main( String args[ ] ) throws SQLException { |
40 | String user = "C##user_id" ; |
41 | String password = "password" ; |
42 | String database = "20.185.147.112:1521/xe" ; |
45 | OracleDataSource ods = new OracleDataSource( ); |
46 | ods.setURL ( "jdbc:oracle:thin:@" + database ); |
48 | ods.setPassword( password ); |
49 | Connection conn = ods.getConnection( ); |
53 | Statement stmt = conn.createStatement( ); |
54 | String query = "select city, description from sales_fact f, stores s, " ; |
55 | query += "products p where (" ; |
56 | if ( args.length == 0 ) query += "brand=' ')" ; |
58 | for ( int i= 0 ; i < args.length; i++ ) |
59 | if ( i == 0 ) query += "brand='" + args[i].trim( ); |
60 | else query += "' or brand='" + args[i].trim( ); |
61 | query += "') and f.product_key=p.product_key and f.store_key=s.store_key" ; |
63 | System.out.println( query + "<b>" ); |
64 | ResultSet rset = stmt.executeQuery( query ); |
67 | while ( rset.next( ) ) { |
69 | System.out.print( rset.getString( 1 ) + "'>" + rset.getString( 2 ) + "<a>" ); |
75 | catch ( SQLException ex ) { |
76 | System.out.println( ex ); |
|
The following Perl script is used to display the corresponding web page based on the city submitted by the GET method.
The command
print "Location: $url\n\n";
tells the browser to redirect to the URL at
$url
.
~/public_html/cgi-bin/jdbc/Hyperlink.pl?city=
|
04 | $city = $query ->url_param( "city" ); |
06 | if ( $city eq "New York" ) { |
09 | elsif ( $city eq "Chicago" ) { |
12 | elsif ( $city eq "Atlanta" ) { |
15 | elsif ( $city eq "Los Angles" ) { |
18 | elsif ( $city eq "San Francisco" ) { |
21 | elsif ( $city eq "Philadelphia" ) { |
27 | print "Location: $url\n\n" ; |
|
Women only call me ugly until they find out how much money I make.
Then they call me ugly and poor.
|