COS 381 Day 23. Agenda  Questions??  Resources Source Code Available for examples in Text Book in Blackboard

Slides:



Advertisements
Similar presentations
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 10 Servlets and Java Server Pages.
Advertisements

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 9 Using Perl for CGI Programming.
WEB DESIGN TABLES, PAGE LAYOUT AND FORMS. Page Layout Page Layout is an important part of web design Why do you think your page layout is important?
Chapter 16 The World Wide Web.
TCP/IP Protocol Suite 1 Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 22 World Wide Web and HTTP.
CGI Programming Part 2. Input Tags Many different ways of getting data from the user. The tag is used most often. has a type attribute –Specifies the.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 14 Web Database Programming Using PHP.
Using Perl for CGI Programming
CIS101 Introduction to Computing Week 05. Agenda Your questions Exam next week - Excel Introduction to the Internet & HTML Online HTML Resources Using.
COS 381 Day 22. Agenda  Assignment #5 Corrected 2 B’s, 1 C, and 3 D’s  Next Capstone progress report due April 21  Capstone projects are DUE May 10.
COS 381 Day 20. Agenda  Assignment #5 Due  Capstone Progress Reports Overdue Were Due April 7  Capstone projects are DUE May 10 at 1PM  Assignment.
Computing Concepts Advanced HTML: Tables and Forms.
COS 381 Day 23. Agenda  Questions??  Resources Source Code Available for examples in Text Book in Blackboard
Cookies & file i/o in perl. Survey (html form in notes)
1 The World Wide Web. 2  Web Fundamentals  Pages are defined by the Hypertext Markup Language (HTML) and contain text, graphics, audio, video and software.
Chapter 10 Maintaining State Information Using Cookies.
CGI Programming: Part 1. What is CGI? CGI = Common Gateway Interface Provides a standardized way for web browsers to: –Call programs on a server. –Pass.
CIS101 Introduction to Computing Week 06. Agenda Your questions Excel Exam during second hour Our status after the snow day Introduction to the Internet.
Chapter 10 Servlets and Java Server Pages. A servlet is a Java class designed to be run in the context of a special servlet container An instance of the.
Christopher M. Pascucci Basic Structural Concepts of.NET Browser – Server Interaction.
Chapter 9 Using Perl for CGI Programming. Computation is required to support sophisticated web applications Computation can be done by the server or the.
Chapter 16 The World Wide Web. 2 Chapter Goals Compare and contrast the Internet and the World Wide Web Describe general Web processing Write basic HTML.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Part 4 Web technologies: HTTP, CGI, PHP,Java applets)
1 HTML and CGI Scripting CSC8304 – Computing Environments for Bioinformatics - Lecture 10.
Chapter 16 The World Wide Web Chapter Goals ( ) Compare and contrast the Internet and the World Wide Web Describe general Web processing.
Chapter 33 CGI Technology for Dynamic Web Documents There are two alternative forms of retrieving web documents. Instead of retrieving static HTML documents,
Chapter 16 The World Wide Web Chapter Goals Compare and contrast the Internet and the World Wide Web Describe general Web processing Describe several.
Server-side Scripting Powering the webs favourite services.
Chapter 16 The World Wide Web. 2 The Web An infrastructure of information combined and the network software used to access it Web page A document that.
CP476 Internet Computing Lecture 5 : HTTP, WWW and URL 1 Lecture 5. WWW, HTTP and URL Objective: to review the concepts of WWW to understand how HTTP works.
XHTML Introductory1 Linking and Publishing Basic Web Pages Chapter 3.
JavaScript, Fourth Edition
5 Chapter Five Web Servers. 5 Chapter Objectives Learn about the Microsoft Personal Web Server Software Learn how to improve Web site performance Learn.
CP476 Internet Computing CGI1 CGI is a common way to provide for specific computations on server side, interactions with users, or access to databases.
CSE 154 LECTURE 12: COOKIES. Including files: include include("filename"); PHP include("header.html"); include("shared-code.php"); PHP inserts the entire.
USING PERL FOR CGI PROGRAMMING
1 In the good old days... Years ago… the WWW was made up of (mostly) static documents. –Each URL corresponded to a single file stored on some hard disk.
Chapter 16 The World Wide Web. 2 The Web is an infrastructure of distributed information combined with software that uses networks as a vehicle to exchange.
Chapter 8 Cookies And Security JavaScript, Third Edition.
Chapter 16 The World Wide Web Chapter Goals Compare and contrast the Internet and the World Wide Web Describe general Web processing Write basic.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 9 Using Perl for CGI Programming.
1 Basic Perl CGI Programming. 2 Issues How and when your program is invoked. Generating Response –HTTP Headers –HTML (or whatever document type you want)
Chapter 6 Server-side Programming: Java Servlets
Cookies Web Browser and Server use HTTP protocol to communicate and HTTP is a stateless protocol. But for a commercial website it is required to maintain.
1 Chapter 9 – Cookies, Sessions, FTP, and More spring into PHP 5 by Steven Holzner Slides were developed by Jack Davis College of Information Science.
11 1 Cookies CGI/Perl Programming By Diane Zak Objectives In this chapter, you will: Learn the difference between temporary and persistent cookies.
Chapter 10 © 2003 by Addison Wesley Longman, Inc. 1 Chapter 10 Using Perl for CGI Programming.
Dr. Azeddine Chikh IS444: Modern tools for applications development.
1 MSCS 237 Overview of web technologies (A specific type of distributed systems)
PHP. $_GET / $_POST / $_SESSION PHP uses predefined variables to provide access to important information about the server and requests from a browser.
XP Tutorial 8 Adding Interactivity with ActionScript.
CP476 Internet Computing CGI1 Cookie –Cookie is a mechanism for a web server recall info of accessing of a client browser –A cookie is an object sent by.
1 WWW. 2 World Wide Web Major application protocol used on the Internet Simple interface Two concepts –Point –Click.
ECMM6018 Enterprise Networking for Electronic Commerce Tutorial 7
Web Design and Development. World Wide Web  World Wide Web (WWW or W3), collection of globally distributed text and multimedia documents and files 
27.1 Chapter 27 WWW and HTTP Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
 2001 Prentice Hall, Inc. All rights reserved. Chapter 7 - Introduction to Common Gateway Interface (CGI) Outline 7.1Introduction 7.2A Simple HTTP Transaction.
Internet Applications (Cont’d) Basic Internet Applications – World Wide Web (WWW) Browser Architecture Static Documents Dynamic Documents Active Documents.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Unit-6 Handling Sessions and Cookies. Concept of Session Session values are store in server side not in user’s machine. A session is available as long.
Session 11: Cookies, Sessions ans Security iNET Academy Open Source Web Development.
27.1 Chapter 27 WWW and HTTP Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
1 Chapter 22 World Wide Web (HTTP) Chapter 22 World Wide Web (HTTP) Mi-Jung Choi Dept. of Computer Science and Engineering
Chapter 5 © 2002 by Addison Wesley Longman, Inc. 1 Chapter 5 Sebesta: Programming the World Wide Web.
Chapter 7 - Introduction to Common Gateway Interface (CGI)
Chapter 27 WWW and HTTP.
10.1 The Common Gateway Interface
Chapter 16 The World Wide Web.
Presentation transcript:

COS 381 Day 23

Agenda  Questions??  Resources Source Code Available for examples in Text Book in Blackboard  In Class Work  Assignment 5 not corrected  Assignment 6 is posted Due Friday, may 2  Quiz 3 covering Perl & XML will be on Friday May 2 Chap 7, 8 & 9 25 M/C  3 rd and final Capstone progress report due  Final Capstone presentation? May 10AM  Continue Discussion on Perl CGI Perl Documentation  Perl Tutorial 

New grading Rubric  Old Exams 7.5 % each)  30% Assignments 5% each)  45% Capstone Project  15% Pre-professional Conduct (see Contract on Classroom Behavior)  10%  New Exams 10 % each)  30% Assignments 7.5% each)  45% Capstone Project  15% Pre-professional Conduct (see Contract on Classroom Behavior)  10%

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 9 Using Perl for CGI Programming

9-5 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley - Tags and their attributes are distributed over the parameters of the function u l(li({-type => "square"},["milk", "bread", "cheese"])); Output: - CGI.pm also includes non-shortcut functions, which produce output for return to the user - A call to header() produces: Content-type: text/html;charset=ISO blank line -- The CGI.pm Module

9-6 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley - The start_html function is used to create the head of the return document, as well as the tag - The parameter to start_html is used as the title of the document start_html("Bill’s Bags"); DOCTYPE html PUBLIC " -//W3C//DTD XHTML 1.0 Transitional//EN " " DTD/xhtml11-transitional.dtd " > Bill’s Bags - The param function is given a widget’s name; it returns the widget’s value - If the query string has name=Abraham in it, param("name") will return "Abraham" - The end_html function generates  SHOW popcorn.html, its display, and popcorn.pl popcorn.htmlpopcorn.pl The CGI.pm Module)

9-7 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 9.4 A Complete Form Example The example includes an HTML page, popcorn.html, for placing an order Also it includes a Perl CGI program for processing the data, popcorn.cgi (note: use.pl not.cgi) Note, to run this example, you must have a web server configured to run CGI programs, you cannot simply browse to the file on your local system

9-8 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Race Condition Process 1 Read Data (2 sec) Increment Data (2 sec) Write Data (2 Sec) Process 2 Read Data (2 sec) Increment Data (2 sec) Write Data (2 Sec) Process 2 Read Data (2 sec) Increment Data (2 sec) Write Data (2 Sec) Data 250 What happens if they all start at the same time? What happens if they start 3, 4 or 5 seconds apart? What do we gave to do to ensure that the process works as intended?

9-9 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Dining Philosophers Five philosophers sit around a circular table. Each philosopher spends his life alternatively thinking and eating. In the centre of the table is a large plate of spaghetti. A philosopher needs two forks to eat a helping of spaghetti. Unfortunately, as philosophy is not as well paid as computing, the philosophers can only afford five forks. One fork is placed between each pair of philosophers and they agree that each will only use the fork to his immediate right and left. What happens when each philosopher grabs a fork?

9-10 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Contention for a resource

9-11 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley - We will use a form to collect survey data from users - The program needs to accumulate survey results which must be stored between form submissions - Store the current results in a file on the server - Because of concurrent use of the file, it must be protected from corruption by blocking other accesses while it is being updated - This can be done with the Perl function, flock, using the parameter value 2 to specify a lock operation and 8 to specify an unlock operation --> SHOW conelec.html and its display conelec.html - Two CGI programs are used for this application, one to collect survey submissions and record the new data, and one to produce the current totals - The file format is eight lines, each having seven values, the first four lines for female responses and the last four lines for male responses 9.5 A Survey Example

9-12 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley File Format

9-13 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley - The program to collect and record form data must: 1. Decode the data in the query string 2. Determine which row of the file must be modified 3. Open, lock, read, the survey data file 4. Split the affected data string into numbers and store them in an array 5. Modify the affected array element and join the array back into a string 6. Rewind the data file 7. ReWrite, unlock, and close the survey data file --> SHOW conelec1.pl conelec1.pl 9.5 A Survey Example (continued)

9-14 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley - Tables are easier to specify with CGI.pm - The table is created with the table function - The border attribute is specified as a parameter - The table’s caption is created with a call to caption, as the second parameter to table - Each row of the table is created with a call to Tr - A heading row is created with a call to th - Data cells are created with calls to td - The calls to Tr, th, and td require references as parameters - Suppose we have three arrays of sales numbers, one for each of three salespersons; each array has one value for each day of the work week - We want to build a table of this information, using CGI.pm 9.5 A Survey Example (continued)

9-15 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley table({-border => "border"}, caption("Sales Figures"), Tr( [th(["Salesperson", "Mon", "Tues", "Wed", "Thu", "Fri"]), ] ) ); 9.5 A Survey Example (continued)

9-16 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley - The program that produces current results must: 1. Open, lock, read the lines into an array of strings, unlock, and close the data file 2. Split the first four rows (responses from females) into arrays of votes for the four age groups 3. Unshift row titles into the vote rows (making them the first elements) 4. Create the column titles row with th and put its address in an array 5. Use td on each rows of votes 6. Push the addresses of the rows of votes onto the row address array 7. Create the table using Tr on the array of row addresses 8. Repeat Steps 2-7 for the last four rows of data (responses from males) --> SHOW conelec2.plconelec2.pl 9.5 A Survey Example (continued)

9-17 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 9.5 A Survey Example The survey example is keeps track of data from a simple survey There are three components conelec.html presents the form and links conelec1.cgi processes a survey conelec2.cgi presents a summary of the results

9-18 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 9.6 Cookies HTTP is a stateless protocol, that is, the server treats each request as completely separate from any other This, however, makes some applications difficult A shopping cart is an object that must be maintained across numerous requests and responses The mechanism of cookies can be used to help maintain state by storing some information on the browser system A cookie is a key/value pair that is keyed to the domain of the server This key/value pair is sent along with any request made by the browser of the same server A cookie has a lifetime which specifies a time at which the cookie is deleted from the browser

9-19 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 9.6 Cookies and Security Cookies are only returned to the server that created them Cookies can be used to determine usage patterns that might not otherwise be ascertained by a server Browsers generally allow users to limit how cookies are used Browsers usually allow users to remove all cookies currently stored by the browser Systems that depend on cookies will fail if the browser refuses to store them

9-20 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 9.6 Cookie Functions The cookie function takes a hash with three keys for the name, value and expiration time of a cookie The cookie value produced by this function must be passed to the header function using the –cookie key header(-cookie => $a_cookie) Calling the cookie function with no arguments produces a hash of all cookies from the current request

9-21 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley - A cookie is an object sent by the server to the client - Cookies are created by some software system on the server (maybe a CGI program) - Every HTTP communication between the browser and the server includes information in its header about the message - At the time a cookie is created, it is given a lifetime - Every time the browser sends a request to the server that created the cookie, while the cookie is still alive, the cookie is included - A browser can be set to reject all cookies - CGI.pm includes support for cookies cookie(-name => a_cookie_name, -value => a_value, -expires => a_time_value); - The name can be any string - The value can be any scalar value - The time is a number followed by a unit code ( d, s, m, h, M, y ) 9.6 Cookies (continued)

9-22 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley - - To fetch the value of one particular cookie, send the cookie’s name to the cookie function $age = cookie( ′ age ′ ); - Example: A cookie that tells the client the time of his or her last visit to this site - Use the Perl function, localtime, to get the parts of time ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime;  SHOW day_cookie.pl day_cookie.pl  SHOW cookie_raider.plcookie_raider.pl  Cookies (continued)

9-23 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley - CGI was once a good way to create animation, but now there are several better ways - There are two ways to use CGI to create animation neither of which requires user intervention 1. Client-pull animation - The client repeatedly requests images from the server, which it displays in sequence - Problems: Internet is not fast enough, and if the approach were widely used, it would pull down the speed of the whole Internet 2. Server-push animation - The server sends the sequence of images to the client, with delays between them - Problems: Also creates a huge load on the Internet, and it is supported only by Netscape 9.7 Animation Using CGI