Client side programming can be problematic because you don't have a ... add
interactivity to a. Web site is through a CGI (Common Gateway Interface) program
.
Web Pub 4
http://www.pint.com/classes/web4
Client Side Helper Applications Netscape Plug-ins ActiveX Controls
Java Applets Scripting Languages * JavaScript * VBScript
Server Side CGI scripts and programs Server API Programs * ISAPI * NSAPI * Apache Modules Java Servlets Server-side scripting * Active Server Pages (ASP) * ColdFusion * PHP
Web Pub 4
http://www.pint.com/classes/web4
Web Pub 4
http://www.pint.com/classes/web4
• • • •
Web is a client-server environment Web browser is typically the client Web server is obviously the server In some ways Web server is a file server, but it could be more of an application server when interactivity is added • There is a question of where the computing in the Web should run. Client side or Server side?
1
Web Pub 4
http://www.pint.com/classes/web4
• Client side programming can be problematic because you don’t have a great deal of control over what the user has – – – –
Screen size Java/JavaScript support Browser differences Hardware
• Server side programming can be problematic because it puts all the responsibility on the server and can cause performance problems • The best approach is a balance with nothing being to heavily relied on particularly client side wise. Everything should be done in a defensive manner.
Web Pub 4
http://www.pint.com/classes/web4
• The most basic server-side way to add interactivity to a Web site is through a CGI (Common Gateway Interface) program. • CGI = Common Gateway Interface • CGI is not the program it is the way things are interfaced • CGI specifies how data should passed in from a Web page and back out • CGI Process 1) User submits form 2) Form is sent to server and eventually CGI program 3) CGI program processes data and responds back 4) Web server passes CGI response to client • The important part is step 2 and the end of step 3 where data goes back and forth.
Web Pub 4
http://www.pint.com/classes/web4
• 2.1 Server determines if request is a document or program • 2.2 Server locates the program and determines if the program can be executed • 2.3 Server starts program (expensive) and sends it the data from form and environment • 2.4 Program runs • 2.5 Server waits for program to finish and takes the result and passes it back to client • Understanding CGI requires an understanding of HTTP and forms
2
Web Pub 4
http://www.pint.com/classes/web4
!
• Pretend to be a Web browser – Telnet www.yourfavoritesite.com 80 – Eventually at the prompt type in • GET / HTTP/1.0 • Hit return twice
– Watch server respond back with headers and then HTML markup
• Key to interaction is the MIME type as indicated by the response header – Content-type: text/html – This header tells the browser what it is “reading”
• To “dynamically make HTML” from a server program just stamp the output with the appropriate MIME type.
Web Pub 4
http://www.pint.com/classes/web4
" • Try http://www.pint.com/cgi-bin/firstcgi.pl This file is a short Perl program like this #!/usr/bin/perl print "Content-type: text/html\n\n"; print"\nFrom CGI\n"; print"\n
Wow! I was created from a CGI program!!
\n
More Stuff
"; print"
\n";
• The key to making this “CGI” was literally the first print statement and the fact it was run on the Web
Web Pub 4
http://www.pint.com/classes/web4
#
$
%
• The output half of CGI is just printing the appropriate HTML markup and headers, the input is slightly harder. • There are two primary ways of getting data into a CGI program – Environment variables – Forms
• When a request takes place headers from the browser and server are combined to create the “environment” This is easily accessible from a programming language. • Demo – http://www.pint.com/cgi-bin/printenv.cgi
3
Web Pub 4
http://www.pint.com/classes/web4
&
'
#
• A form is enclosed by and • The various elements that make up a form are called controls according to the W3C specification. A more common expression is fields. • The element has three basic attributes which determine what to do when the form is being submitted – ACTION - specifies where the form will be sent in the form of a URL • •