Presentation is loading. Please wait.

Presentation is loading. Please wait.

LING 408/508: Computational Techniques for Linguists

Similar presentations


Presentation on theme: "LING 408/508: Computational Techniques for Linguists"— Presentation transcript:

1 LING 408/508: Computational Techniques for Linguists
Lecture 21

2 Administrivia Both Homework 7 and 8 have been graded Homework 9 today

3 Example: example.cgi SiteSites$ ./example.cgi Content-Type: text/html; charset=utf-8 <html><head></head> <body><h1>~sandiway/Sites/example.cgi</h1> <p>Now: Tue Oct 30 20:37:01 MST 2018 </p> <p>User: sandiway <script src="canvasjs.min.js"></script> <div id="cc" style="height: 400px; max-width: 600px; margin: 0px auto;"></div> <script> window.onload = function() { var chart = new CanvasJS.Chart("cc", { animationEnabled: true, title: { text: "Disk Space: MB" }, data: [{ type: "pie", startAngle: 240, yValueFormatString: "##0.00'%'", indexLabel: "{label} {y}", dataPoints: [ {y: / *100, label: "Used", color: "Bisque"}, {y: / *100, label: "Unused", color: "Tan"} ]}]} ); chart.render(); } </script></body></html>

4 Example: example.cgi $2 $3 $4

5 Example: example.cgi Used the free(?) canvasjs.min.js library from They have source code for many examples of javascript charts. Wondering what happens after 30 days…

6 Today's Topics Sending form data to the webserver using:
GET method POST method There are also (many) other methods to communicate information depending on the kind of webserver we run: e.g. Apache Tomcat (for Java) e.g. WebSocket interface (for bidirectional data passing) etc.

7 Sending information using GET
HTML form: <form action=" method="GET"> First: <input type="text" name="first" size=12> Last: <input type="text" name="last" size=12> <input type="submit"> </form> Information encoded using alphanumeric characters: why? URLs are restricted to alphanumeric characters only bash accesses the URL-encoded string via the environment variable QUERY_STRING

8 Sending information using GET
get.cgi: #!/bin/bash echo "Content-Type: text/plain" echo #echo $QUERY_STRING origIFS=$IFS IFS='=&' set -- $QUERY_STRING IFS=$origIFS echo "1:<$1> 2:<$2> 3:<$3> 4:<$4>" = and & In bash: IFS = internal field separator (for arguments) default: space newline tab set -- String -- option: positional parameters $1,$2,..etc. are set after splitting String

9 Sending information using GET
get.cgi: #!/bin/bash echo "Content-Type: text/plain" echo #echo $QUERY_STRING origIFS=$IFS IFS='=&' set -- $QUERY_STRING IFS=$origIFS echo "1:<$1> 2:<$2> 3:<$3> 4:<$4>"

10 Sending information using GET
OS X /Library/WebServer/CGI-Executables/ $ls -l get.cgi -rwxr-xr-x 1 root wheel 161 Oct get.cgi sudo chmod 755 get.cgi Ubuntu /usr/lib/cgi-bin/

11 Sending information using POST

12 Sending information using POST
HTML form: <form action=" method="POST"> First: <input type="text" name="first" size=12> Last: <input type="text" name="last" size=12> <input type="submit"> </form> bash accesses the URL-encoded string on standard input via read cf. GET using QUERY_STRING

13 Sending information using POST
bash accesses the URL-encoded string on standard input via read read.cgi: #!/bin/bash echo "Content-Type: text/plain" echo read input origIFS=$IFS IFS='=&' set -- $input IFS=$origIFS echo "<$2><$4>"

14 Sending information using POST
Client-side code: Server-side code: read.cgi: #!/bin/bash echo "Content-Type: text/plain" echo read input origIFS=$IFS IFS='=&' set -- $input IFS=$origIFS echo "<$2><$4>"

15 Limitations of positional parameters
set values: origIFS=$IFS IFS='=&' set -- $QUERY_STRING IFS=$origIFS echo "1:<$1> 2:<$2> 3:<$3> 4:<$4>"

16 Files and Locations Server cgi-bin directory: Webserver logs:
MacOS: /Library/WebServer/CGI-Executables Ubuntu: /usr/lib/cgi-bin Webserver logs: MacOS: /var/log/apache2/error_log Ubuntu: /var/log/apache2/error.log Course webpage: form-get.html form-post.html get.cgi (needs 755 permissions) read.cgi (needs 755 permissions)

17 Error Log Example: error log: …
[Wed Oct 31 22:08: ] [cgi:error] [pid 4600] [client ::1:51340] AH01215: (13)Permission denied: exec of '/Users/sandiway/Sites/get2.cgi' failed: /Users/sandiway/Sites/get2.cgi [Wed Oct 31 22:08: ] [cgi:error] [pid 4600] [client ::1:51340] End of script output before headers: get2.cgi

18 Homework 9 Use the cgi-bin methods to implement a BMI bash shell script on the webserver. i.e. you should modify your BMI program to accept data from a html form and compute the value on the server side Use both GET and POST methods to communicate the weight, height and units. Submit your .html and .cgi files Submit screenshots to show it working in both cases Due next Monday by midnight

19 Example: adding names to a server list
Normally, you'd set up database software,e.g. mysql, on the webserver

20 Example: adding names to a server list
Server-side code: get2.cgi Client-side code: addnames.html Data file: touch names-list.txt chmod a+w names-list.txt


Download ppt "LING 408/508: Computational Techniques for Linguists"

Similar presentations


Ads by Google