Server-side computing

Similar documents
CGI Programming. What is "CGI"?

CS105 Perl: Perl CGI. Nathan Clement 24 Feb 2014

COSC 2206 Internet Tools. The HTTP Protocol

Hands-On Perl Scripting and CGI Programming

3. WWW and HTTP. Fig.3.1 Architecture of WWW

COMS 359: Interactive Media

Server-Side Web Programming: Python (Part 1) Copyright 2017 by Robert M. Dondero, Ph.D. Princeton University

Networking and Internet

Lecture 9a: Sessions and Cookies

Programming the World Wide Web by Robert W. Sebesta

HTTP and HTML. We will use HTML as a frontend to our webapplications, therefore a basic knowledge of HTML is required, especially in forms.

HTML HTML. Chris Seddon CRS Enterprises Ltd 1

Course Topics. The Three-Tier Architecture. Example 1: Airline reservations. IT360: Applied Database Systems. Introduction to PHP

Outline. Introducing Form. Introducing Forms 2/21/2013 INTRODUCTION TO WEB DEVELOPMENT AND HTML

Copyright 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Chapter 2 Introduction to XHTML

UNIT I. A protocol is a precise set of rules defining how components communicate, the format of addresses, how data is split into packets

2.1 Origins and Evolution of HTML

CGI Architecture Diagram. Web browser takes response from web server and displays either the received file or error message.

Computer Networks. Wenzhong Li. Nanjing University

Static Webpage Development

CHAPTER 2 MARKUP LANGUAGES: XHTML 1.0

Programming the Web 06CS73 INTRODUCTION AND OVERVIEW. Dr. Kavi Mahesh, PESIT, Bangalore. Textbook: Programming the World Wide Web

Web Programming. Based on Notes by D. Hollinger Also Java Network Programming and Distributed Computing, Chs.. 9,10 Also Online Java Tutorial, Sun.

Chapter 10 Servlets and Java Server Pages

CERTIFICATE IN WEB PROGRAMMING

Summary 4/5. (contains info about the html)

A Brief Introduction to HTML

Java Applets, etc. Instructor: Dmitri A. Gusev. Fall Lecture 25, December 5, CS 502: Computers and Communications Technology

1.264 Lecture 12. HTML Introduction to FrontPage

Copyright 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Chapter 11 Introduction to PHP

2.1 Origins and Evolution of HTML

PHP CURRICULUM 6 WEEKS

2.1 Origins and Evolution of HTML. 2.3 HTML Document Structure

Basic HTML. Lecture 14. Robb T. Koether. Hampden-Sydney College. Wed, Feb 20, 2013

Basic HTML. Lecture 14. Robb T. Koether. Hampden-Sydney College. Wed, Feb 20, 2013

Introduction. Server-side Techniques. Introduction. 2 modes in the PHP processor:

1.1 A Brief Intro to the Internet

Web, HTTP and Web Caching

( A ) 8. If the address of an array is stored in $value, how do you get the values of this array? (B) \$value (C) &$value (D) $$value

NETB 329 Lecture 13 Python CGI Programming

Basic HTML Lecture 14

Real Life Web Development. Joseph Paul Cohen

PHP + ANGULAR4 CURRICULUM 6 WEEKS

World Wide Web, etc.

CSCB20 Week 8. Introduction to Database and Web Application Programming. Anna Bretscher* Winter 2017

Saving State on the WWW

Lecture 7b: HTTP. Feb. 24, Internet and Intranet Protocols and Applications

Islamic University of Gaza Faculty of Engineering Department of Computer Engineering ECOM Advanced Internet Technology Lab.

CSI 3140 WWW Structures, Techniques and Standards. Markup Languages: XHTML 1.0

Web development using PHP & MySQL with HTML5, CSS, JavaScript

Hypertext Transport Protocol

ICOM 5016 Database Systems. Database Users. User Interfaces and Tools. Chapter 8: Application Design and Development.

COMP284 Practical 3 Perl (3)

First Simple Interactive JSP example

Web technologies. Web. basic components. embellishments in browser. DOM (document object model)

Lecture 12. PHP. cp476 PHP

D B M G. Introduction to databases. Web programming: the HTML language. Web programming. The HTML Politecnico di Torino 1

CNIT 129S: Securing Web Applications. Ch 3: Web Application Technologies

2.1 Origins and Evolution of HTML

Unit 5 Web Publishing Systems Page 1 of 13 Part 4 HTML Part 4

- Origins - Rasmus Lerdorf Developed to allow him to track visitors to his Web site

Data Presentation and Markup Languages

Javascript, Java, Flash, Silverlight, HTML5 (animation, audio/video, ) Ajax (asynchronous Javascript and XML)

IT350 Web & Internet Programming. Fall 2012

INSTITUTE OF AERONAUTICAL ENGINEERING (Autonomous) Dundigal, Hyderabad

1.1 A Brief Intro to the Internet

SAS Solutions for the Web: Static and Dynamic Alternatives Matthew Grover, S-Street Consulting, Inc.

introduction to XHTML

Database Applications

CMSC 332 Computer Networking Web and FTP

Web Technology. HTML & xhtml

About the Authors. Who Should Read This Book. How This Book Is Organized

CMPE 151: Network Administration. Servers

Session 8. Reading and Reference. en.wikipedia.org/wiki/list_of_http_headers. en.wikipedia.org/wiki/http_status_codes

(Refer Slide Time: 01:41) (Refer Slide Time: 01:42)

HTML Summary. All of the following are containers. Structure. Italics Bold. Line Break. Horizontal Rule. Non-break (hard) space.

Creating Web Pages. Getting Started

Web Technology. COMP476 Networked Computer Systems. Hypertext and Hypermedia. Document Representation. Client-Server Paradigm.

The University of Nottingham

HTML. HTML Evolution

Web Programming Paper Solution (Chapter wise)

Web Programming 3. Object Oriented Interface to CGI.pm. Generating Images. Using Headers. Using Cookies. Hidden fields.

Outline of Lecture 5. Course Content. Objectives of Lecture 6 CGI and HTML Forms

Creating A Web Page. Computer Concepts I and II. Sue Norris

Web Engineering. Basic Technologies: Protocols and Web Servers. Husni

Web Programming 4) PHP and the Web

Web Programming with CGI.pm. Executing CGI scripts

WML2.0 TUTORIAL. The XHTML Basic defined by the W3C is a proper subset of XHTML, which is a reformulation of HTML in XML.

Web System and Technologies (Objective + Subjective)

recall: a Web page is a text document that contains additional formatting information in the HyperText Markup Language (HTML)

Course Topics. IT360: Applied Database Systems. Introduction to PHP

Integrate Word and the Web Vocabulary

COPYRIGHTED MATERIAL. The Basics of HTML. What Is the World Wide Web?

EEC-682/782 Computer Networks I

Lecture : 3. Practical : 2. Course Credit. Tutorial : 0. Total : 5. Course Learning Outcomes

Session 9. Data Sharing & Cookies. Reading & Reference. Reading. Reference http state management. Session 9 Data Sharing

CST272 Getting Started Page 1

Chapter 7:- PHP. Compiled By:- Sanjay Patel Assistant Professor, SVBIT.

Web Publishing Basics I

Planning and Designing Your Site p. 109 Design Concepts p. 116 Summary p. 118 Defining Your Site p. 119 The Files Panel p. 119 Accessing Your Remote

Transcription:

Server-side computing Why server-side? Approaches 1 Why server-side? Markup languages cannot Specify Computations Interactions with users Provide access to Server-side resources Databases Programs Services 2

Approaches programmer centered designer centered 3 programmer centered Document generation inside computation code CGI Java servlets 4

designer centered Computation code inside document template PHP ASP JSP 5 CGI: the Common Gateway Intefrace Let browsers request server-side execution Open source LAMP Linux, Apache, MySQL, Px Px Perl, PHP, Python 6

ASP or ASP.NET: Active Server Pages Microsoft 7 JSP: Java Server Pages Similar to ASP and ASP.NET Java-based Sun Microsystems 8

CGI Interface between browser and server HTTP request ==> Program instead of document Server recognizes by file Location Special directories Extension 9 CGI program Often stored in cgi-bin directory Produce complete HTTP response, or just URL of existing doc 10

CGI linkage Some CGI programs in machine code Perl programs usually kept in source form ==> must be run perl on them 11 source file can be made executable add line at beginning specifies language processing run first 12

For Perl programs if perl in /usr/local/bin/perl often in UNIX ==> #!/usr/local/bin/perl -w 13 for Perl CGI programs sometimes use file extension.cgi e.g., for the CGI Wrap system 14

HTML document specifies CGI program with hypertext reference attribute href, of anchor tag, <a> as in <a href =./cgi-bin/reply.cgi>" Click here to run the CGI program, reply.pl </a> 15 Communications and computation using CGI 16

Model... Browser server application Form Submit completed form Call CGI CGI CGI program's response CGI program's response 17 18

<!-- reply.html - calls a trivial cgi program --> <html> <head> <title> HTML to call the CGI-Perl program reply.cgi </title> </head> <body> This is our first CGI-Perl example <a href = "./cgi-bin/reply.cgi"> Click here to run the CGI program, reply.cgi </a> </body> </html> 19 CGI --> browser connection from CGI program back to requesting browser Through STDOUT Through server HTTP header needs only content type followed by blank line print "Content-type: text/html \n\n"; SHOW reply.cgi 20

Query string names and values of widgets values always coded as strings format of name/value pair name=value If form has more than one widget ==> values separated with ampersands milk=2&payment=visa special characters coded percent sign + two-character hexadecimal number = ASCII code of character Some browsers code spaces as + signs rather than as %20 get versus post HTTP methods 21 GET vs. POST... GET + Access CGI prog. w/ query without a form Pass parameters to program... Can send extra path info... Query might get truncated Post + Unlimited query length No canned queries (hard-coded url) 22

The CGI.pm Module - A Perl module serves as a library - Can be used as a function library or a class library - Get info about by typing perldoc CGI - The Perl use declaration is used to make a module available to a program - To make only part of a module available, specify the part name after a colon (For our purposes, only the standard part of the CGI module is needed) use CGI ":standard"; - Common Functions 23 The CGI.pm Module Perl module serves as library Can be used as function library or class library Info: perldoc CGI 24

Perl use declaration make module available to program to make only part of module available specify part name after colon For our purposes only need standard part of CGI module use CGI ":standard"; 25 Common CGI.pm Functions Shortcut functions produce tags using their parameters as attribute values br; returns "<br/>" 26

e.g., h2("very easy!"); returns <h2> Very easy! </h2> parameter to function h2 used as content of <h2> tag 27 function output to return doc call must be parameter to print print h2("very easy!"); 28

Tags can have both content and attributes Each attribute passed as name/value pair just as in hash literal Attribute names passed with preceding dash 29 textarea(-name => "Description", -rows => "2", -cols => "35" ); Produces: <textarea name ="Description" rows=2 cols=35> </textarea> 30

If both content and attributes passed to function attributes specified in hash literal as first parameter a({-href => "fruit.html"}, "Press here for fruit descriptions"); Output: <a href="fruit.html"> Press here for fruit descriptions</a> 31 Tags and their attributes distributed over parameters of function ol(li({-type => "square"}, ["milk", "bread", "cheese"])); Output: <ol> <li type="square >milk</li> <li type="square >bread</li> <li type="square >cheese</li> </ol> 32

CGI.pm also includes non-shortcut functions produce output for return to user call to header() produces: Content-type: text/html;charset=iso- 8859-1 -- blank line -- 33 The start_html function create head of return document <body> tag parameter to start_html used as title of document start_html("bill s Bags"); 34

DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.0 //EN" "http://www.w3.org/tr/xhtml-basic/ xhtml-basic10.dtd"> <html xmlns= "http://www.w3.org/1999/xhtml lang="en-us"> <head><title>bill s Bags</title> </head> <body> 35 The param function given a widget s name returns widget s value If, e.g., query string has name=abraham in it, param("name") will return "Abraham" 36

The end_html function generates </body></html> SHOW popcorn.html display popcorn.cgi 37 FIGURE 10.2 Display of popcorn.html 38

FIGURE 10.3 Display of popcorn.html, form filled out 39 FIGURE 10.4 Output of popcorn.cgi 40

A Survey Example - Use form to collect survey data from users - accumulate survey results, stored between form submissions in file on server 41 concurrent use of file ==> must be protected from corruption block other accesses while being updated Under UNIX, Perl function flock 42

parameter values for flock defined in Perl Fcntl module (write lock is LOCK_EX) To update file open file lock with flock modify rewind with seek close file --> SHOW conelec.html + display 43 Two CGI programs used 1. collect survey submissions and record new data 2. produce current totals file format eight lines each w/ 7 values first four for female responses last four for male responses 44

FIGURE 10.5 Display of conelec.html 45 To collect and record form data must: 1. Get form values (with param) 2. Determine row of file to be modified 3. Open, lock, and read survey data file 4. Split affected data string into numbers + store them in array 46

5. Modify affected array element & join array back into string (use gender to determine which half of data affected) 6. Rewind data file (with seek) 7. Rewrite and close survey data file --> SHOW conelec1.pl 47 Tables easier to specify with CGI.pm - table created with table function - border attribute specified as parameter - table s caption created with call to caption, as second parameter to table 48

- Each row of table is created with call to Tr - heading row created with call to th - Data cells created with calls to td - calls to Tr, th, and td require references as parameters 49 - Suppose have three arrays of sales numbers - one for each of three salespersons - each array has one value for each day of work week - want to build table of this information - using CGI.pm 50

table({-border => "border"}, caption("sales Figures"), Tr( [th(["salesperson", "Mon", "Tues", "Wed", "Thu", "Fri"]), th("mary").td(\@marysales), th("freddie").td(\@freddiesales), th("spot").td(\@spotsales), ] ) ); 51 program that produces current results must: 1. Open file and read lines into array of strings 2. Split first four rows (responses from females) into arrays of votes for four age groups 3. Unshift row titles into vote rows (making them first elements) 4. Create column titles row with th put its address in array 52

5. Use td on each rows of votes 6. Push addresses of rows of votes onto row address array 7. Create table using Tr on array of row addresses 8. Repeat Steps 2-7 for last four rows of data (responses from males) 53 --> SHOW conelec2.cgi --> SHOW Figure 10.7 54

FIGURE 10.7 Survey results page 55 10.6 Cookies - session = time span during which browser interacts with particular server - HTTP protocol is stateless - But, several reasons why useful for server to relate request to session - Shopping carts for many different simultaneous customers - Customer profiling for advertising - Customized interfaces for specific clients 56

Approaches to storing client information: - Store on server - too much to store! - Store on client machine - this works 57 cookie = small object of information name and text value created by some software system on server (maybe CGI program) Every HTTP communication between browser and server includes information in header about message when cookie created given lifetime Every time browser sends request to server that created cookie, while cookie is still alive cookie included 58

browser can be set to reject cookies - CGI.pm includes support for cookies cookie(-name => a_cookie_name, -value => a_value, -expires => a_time_value); - name can be any string - value can be any scalar value - time is a number followed by a unit code (d, s, m, h, M, y) 59 Cookies must be placed in HTTP header when header created header(-cookie => $my_cookie); To fetch cookies from HTTP request call cookie with no parameters hash of all current cookies returned To fetch value of one particular cookie send cookie s name to cookie function $age = cookie( age ); 60

Example: cookie that tells customer time of last visit to this site Use Perl function, localtime to get parts of time ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime; SHOW time_date.pl 61 CGI program to solve our problem: 1. Get cookie named last_time 2. Get current day of week month day of month & put them in cookie named last_time 3. Put cookie in header of return document 62

4. If no existing cookie produce welcome message for first-time visitor 5. If there was cookie produce welcome message includes previous day of week month day of month SHOW day_cookie.pl 63