Presentation is loading. Please wait.

Presentation is loading. Please wait.

LING 408/508: Programming for Linguists Lecture 17 October 21 st.

Similar presentations


Presentation on theme: "LING 408/508: Programming for Linguists Lecture 17 October 21 st."— Presentation transcript:

1 LING 408/508: Programming for Linguists Lecture 17 October 21 st

2 Administrivia No class all next week

3 Last Time We enabled our first Web server: –sudo apachectl –k start Do we all have our webservers up and running?

4 Last Time Client: ~sandiway/Desktop/form.html Server: /Library/Webserver/CGI- Executables/program.cgi Content-type: text/plain http://localhost/cgi-bin/program.cgi?first=Sandiway&last=Fong $QUERY_STRING sudo chmod 755 program.cgi

5 Sending information: GET program.cgi: #!/bin/bash echo "Content-type: text/plain" echo #echo $QUERY_STRING origIFS=$IFS IFS='=&' set -- $QUERY_STRING IFS=$origIFS echo "1: 2: 3: 4: " In bash: IFS = internal field separator (for arguments) default: space newline tab set – String -- option: positional parameters are set after parsing String

6 Sending information: POST HTML form: First: Last: bash accesses the URL-encoded string on standard input via read

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

8 Other webservers Perl module PHP module Tomcat (Java)

9 mod_perl Apache webserver module with Perl – not enabled by default /etc/apache2/httpd.conf (on OSX) #LoadModule perl_module libexec/apache2/mod_perl.so Add to httpd.conf: – PerlModule Apache2::Status – – SetHandler perl-script – PerlHandler Apache2::Status –

10 mod_perl http://localhost/perl-status

11 Registry Scripts Add to httpd.conf: SetHandler perl-script PerlResponseHandler ModPerl::Registry PerlOptions +ParseHeaders Options +ExecCGI Order allow,deny Allow from all

12 Registry Scripts perl/test.pl(/Library/WebServer/Documents/) #!/usr/bin/perl print "Content-type: text/plain\n\n"; print "Test Perl program works!\n"; URL: http://localhost/perl/test.pl

13 Other webservers Perl module PHP module Tomcat (Java)

14 Tomcat JSP = JavaServer Pages (HTML with embedded Java code) Apache Tomcat: a JSP webserver from Apache – http://tomcat.apache.org (8.0) http://tomcat.apache.org Install: – /usr/local/apache-tomcat-8.0.12/ Subdirectories: – webapps/(put app.war files here – like a bundle) – webapps/ROOT/(.jsp.html files can go directly here too) – logs/catalina.out(log output from java, – e.g. print statements) – lib/(common.class files can go here) – bin/startup.sh(start webserver) – bin/shutdown.sh(stop webserver)

15 class files Class Loader HOW-TO – common unpacked classes and resources in $CATALINA_BASE/lib – http://tomcat.apache.org/tomcat-8.0-doc/class- loader-howto.html

16 mixing Java and html Tags: – Scriptlets: – Java code – evaluate expression – declarations – include directive – page directive, e.g. import="java.util.*" Predefined variables: – out.println() – request.getRemoteHost() – response.sendRedirect()

17 forms and sessions Webpage (client side): process.jsp (server side): <% String name = request.getParameter( "username" ); session.setAttribute( "yourName", name ); %> Some other.jsp file (server side):

18 beans class with methods for setting and getting field names of forms Form field: Define a class with standardized naming: public class UserData { String username; public void setUsername( String value ) { username = value; } public String getUsername() { return username; } } Storage: Retrieval:

19 Example Stanford Parser:

20 Homework 5 Use cgi-bin to implement your BMI shell script Use both GET and POST methods Send me your code next week Hard to evaluate: – Demonstrate in it class


Download ppt "LING 408/508: Programming for Linguists Lecture 17 October 21 st."

Similar presentations


Ads by Google