Date post: | 26-Dec-2015 |
Category: |
Documents |
Upload: | horace-neal-bates |
View: | 219 times |
Download: | 1 times |
LING 408/508: Programming for Linguists
Lecture 17October 21st
Administrivia
• No class all next week
Last Time
• We enabled our first Web server:– sudo apachectl –k start
• Do we all have our webservers up and running?
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 755program.cgi
Sending information: GET
• program.cgi:#!/bin/bashecho "Content-type: text/plain"echo#echo $QUERY_STRINGorigIFS=$IFSIFS='=&'set -- $QUERY_STRINGIFS=$origIFSecho "1:<$1> 2:<$2> 3:<$3> 4:<$4>"
In bash:IFS = internal field separator (for arguments)default: space newline tabset – String -- option: positional parameters are set after parsing String
Sending information: POST
• HTML form:<form action="http://localhost/cgi-bin/read.cgi" 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
Sending information: POST
• bash accesses the URL-encoded string on standard input via read
• Example read.cgi:#!/bin/bashecho "Content-Type: text/plain"echoread inputorigIFS=$IFSIFS='=&'set -- $inputIFS=$origIFSecho "<$2><$4>"
Other webservers
• Perl module• PHP module• Tomcat (Java)
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– <Location /perl-status>– SetHandler perl-script– PerlHandler Apache2::Status– </Location>
mod_perlhttp://localhost/perl-status
Registry Scripts
Add to httpd.conf:• <Location /perl/>• SetHandler perl-script• PerlResponseHandler ModPerl::Registry• PerlOptions +ParseHeaders• Options +ExecCGI• Order allow,deny• Allow from all • </Location>
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
Other webservers
• Perl module• PHP module• Tomcat (Java)
Tomcat• JSP = JavaServer Pages (HTML with embedded Java code)• Apache Tomcat: a JSP webserver from Apache
– http://tomcat.apache.org (8.0)• 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)
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
mixing Java and html• Tags:
– <jsp:include page="hello.jsp"/>• Scriptlets:
– <% … %> Java code– <%= … %> evaluate expression– <%! … %> declarations– <%@ include file=".." %> include directive– <%@ page … %> page directive, e.g. import="java.util.*"Predefined variables:– out.println()– request.getRemoteHost()– response.sendRedirect()
forms and sessions
Webpage (client side):• <form action="process.jsp">• <INPUT TYPE=TEXT NAME=username>• </form>
process.jsp (server side):• <% String name = request.getParameter( "username" );• session.setAttribute( "yourName", name ); %>
Some other .jsp file (server side):• <%= session.getAttribute( "yourName" ) %>
beans• class with methods for setting and getting field names of formsForm field:• <INPUT TYPE=TEXT NAME=username>Define a class with standardized naming:• public class UserData {• String username;
• public void setUsername( String value )• {• username = value;• }• public String getUsername() { return username; }• }Storage:• <jsp:useBean id="user" class="user.UserData" scope="session"/>• <jsp:setProperty name="user" property="*"/> Retrieval:• <jsp:useBean id="user" class="user.UserData" scope="session"/> • <%= user.getUsername() %>
Example
• Stanford Parser:
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