Скачать презентацию Lecture Server-side Programming CGI Common Gateway Interface 1 Скачать презентацию Lecture Server-side Programming CGI Common Gateway Interface 1

c76805774c868c07a56bb71e507f3d79.ppt

  • Количество слайдов: 29

Lecture Server-side Programming CGI Common Gateway Interface 1 Lecture Server-side Programming CGI Common Gateway Interface 1

Rich Internet Applications An RIA is a web application that provides the client with Rich Internet Applications An RIA is a web application that provides the client with the features and functionality of desktop applications Requires transferring the processing from the server to the client Javascript is one enabling technology for a RIA

RIAs in the Internet client-server model Client (browser) Web server HTTP request for resource RIAs in the Internet client-server model Client (browser) Web server HTTP request for resource Client does all the processing (eg play videos as they come in) Server sends code but keeps data Data (eg multimedia) stay on the server

Some technologies that support RIA development Javascript (and associated ECMA dialects) Adobe Flash player Some technologies that support RIA development Javascript (and associated ECMA dialects) Adobe Flash player and IDE Java Applets and Java Webstart (see later) AJAX Asynchronous Java. Script and XML

Server-Side Programming Lots of programs/applications designed to run on the machines on which they Server-Side Programming Lots of programs/applications designed to run on the machines on which they are installed How can a remote client request access to these?

CGI programming CGI => Common Gateway Interface A protocol for interfacing local applications with CGI programming CGI => Common Gateway Interface A protocol for interfacing local applications with a web server Sequence of steps Client sends URL request Program runs at the server side Output is collected and sent back to the client Often the output is an HTML “built” by the server

CGI using HTML and C language Why do we need CGI? To read the CGI using HTML and C language Why do we need CGI? To read the information on the forms (HTML) To build a customised HTML response to users To understand the concept lets use C at first. . . CGI is completely independent of the language and OS CGI is implemented in (almost) all webservers

CGI programs can be written in any language supported by the server. This includes CGI programs can be written in any language supported by the server. This includes compiled programming languages, such as C and C++; interpreted languages, such as Perl, Python, Ruby, and languages, such as Java, that lie somewhere in between.

Hello World! #include <iostream> using namespace std; int main(void) { cout << Hello World! #include using namespace std; int main(void) { cout << "Content-Type: text/html; charset=us-asciinn"; /** Print the HTML response page to STDOUT. **/ cout << "n"; cout << "CGI Outputn"; cout << "n" ; cout << "Hello, world. n"; cout << "this is my first CGI" << "n"; cout << "n"; cout << "n"; return 0; } Compile, then place the executable inside cgi-bin directory of xitami Test using a browser, URL: http: //localhost: 8080/cgi-bin/helloworld

How to submit data using forms GET http: //www. someurl/cgi-bin/script? var 1=1&var 2=4 Web How to submit data using forms GET http: //www. someurl/cgi-bin/script? var 1=1&var 2=4 Web server has a special directory called cgi-bin Two variables: var 1=1 var 2=4 Special characters are encoded ~ would be encoded as %7 E (% followed by ASCII code)

GET So variables from the forms go on URL The environment variable is: $QUERY_STRING GET So variables from the forms go on URL The environment variable is: $QUERY_STRING Most browsers limit the size of URLs (256 chars, some more, e. g. , IE is 2083 chars) When you have too much data, use POST instead. . .