Download presentation
Presentation is loading. Please wait.
Published byNickolas Osborne Modified over 9 years ago
1
2006 Pearson Education, Inc. All rights reserved. 1 19 Web Programming
2
2006 Pearson Education, Inc. All rights reserved. 2 This is the common air that bathes the globe. — Walt Whitman The longest part of the journey is said to be the passing of the gate. — Marcus Terentius Varro Railway termini... are our gates to the glorious and unknown. Through them we pass out into adventure and sunshine, to them, alas! we return. — E. M. Forster There comes a time in a man’s life when to get where he has to go—if there are no doors or windows—he walks through a wall. — Bernard Malamud
3
2006 Pearson Education, Inc. All rights reserved. 3 OBJECTIVES In this chapter you will learn: The Common Gateway Interface (CGI) protocol. The Hypertext Transfer Protocol (HTTP) and HTTP headers. Web server's functionality. The Apache HTTP Server. To request documents from a Web server. To implement CGI scripts. To send input to CGI scripts using XHTML forms.
4
2006 Pearson Education, Inc. All rights reserved. 4 19.1 Introduction 19.2 HTTP Request Types 19.3 Multitier Architecture 19.4 Accessing Web Servers 19.5 Apache HTTP Server 19.6 Requesting XHTML Documents 19.7 Introduction to CGI 19.8 Simple HTTP Transactions 19.9 Simple CGI Scripts 19.10 Sending Input to a CGI Script 19.11 Using XHTML Forms to Send Input 19.12 Other Headers 19.13 Case Study: An Interactive Web Page 19.14 Cookies 19.15 Server-Side Files 19.16 Case Study: Shopping Cart 19.17 Wrap-Up 19.18 Internet and Web Resources
5
2006 Pearson Education, Inc. All rights reserved. 5 Software Engineering Observation 19.1 The data sent in a post request is not part of the URL and cannot be seen by users. Forms that contain many fields often are submitted to Web servers via post requests. Sensitive form fields, such as passwords, should be sent using this request type.
6
2006 Pearson Education, Inc. All rights reserved. 6 Fig. 19.1 | HTTP’s other request types.
7
2006 Pearson Education, Inc. All rights reserved. 7 Fig. 19.2 | Three-tier application model.
8
2006 Pearson Education, Inc. All rights reserved. 8 Fig. 19.3 | Requesting test.html from Apache.
9
2006 Pearson Education, Inc. All rights reserved. 9 Fig. 19.4 | Client interacting with server and Web server. Step 1: The get request, GET /books/downloads.html HTTP/1.1. (Part 1 of 2.)
10
2006 Pearson Education, Inc. All rights reserved. 10 Fig. 19.4 | Client interacting with server and Web server. Step 2: The HTTP response, HTTP/1.1 200 OK. (Part 2 of 2.)
11
2006 Pearson Education, Inc. All rights reserved. 11 Outline localtime.cpp (1 of 2)
12
2006 Pearson Education, Inc. All rights reserved. 12 Outline localtime.cpp (2 of 2)
13
2006 Pearson Education, Inc. All rights reserved. 13 Fig. 19.6 | Step 1: The get request, GET /cgi-bin/localtime.cgi HTTP/1.1. (Part 1 of 4.)
14
2006 Pearson Education, Inc. All rights reserved. 14 Fig. 19.6 | Step 2: The Web server starts the CGI script. (Part 2 of 4.)
15
2006 Pearson Education, Inc. All rights reserved. 15 Fig. 19.6 | Step 3: The script output is sent to the Web server. (Part 3 of 4.)
16
2006 Pearson Education, Inc. All rights reserved. 16 Fig. 19.6 | Step 4: The HTTP response, HTTP/1.1 200 OK. (Part 4 of 4.)
17
2006 Pearson Education, Inc. All rights reserved. 17 Common Programming Error 19.1 Forgetting to place a blank line after a header is a syntax error.
18
2006 Pearson Education, Inc. All rights reserved. 18 Fig. 19.7 | Output of localtime.cgi when executed from the command line.
19
2006 Pearson Education, Inc. All rights reserved. 19 Outline environment.cpp (1 of 4)
20
2006 Pearson Education, Inc. All rights reserved. 20 Outline environment.cpp (2 of 4)
21
2006 Pearson Education, Inc. All rights reserved. 21 Outline environment.cpp (3 of 4)
22
2006 Pearson Education, Inc. All rights reserved. 22 Outline environment.cpp (4 of 4)
23
2006 Pearson Education, Inc. All rights reserved. 23 Outline querystring.cpp (1 of 3)
24
2006 Pearson Education, Inc. All rights reserved. 24 Outline querystring.cpp (2 of 3)
25
2006 Pearson Education, Inc. All rights reserved. 25 Outline querystring.cpp (3 of 3)
26
2006 Pearson Education, Inc. All rights reserved. 26 Fig. 19.10 | XHTML form elements. (Part 1 of 2)
27
2006 Pearson Education, Inc. All rights reserved. 27 Fig. 19.10 | XHTML form elements. (Part 2 of 2)
28
2006 Pearson Education, Inc. All rights reserved. 28 Outline getquery.cpp (1 of 4)
29
2006 Pearson Education, Inc. All rights reserved. 29 Outline getquery.cpp (2 of 4)
30
2006 Pearson Education, Inc. All rights reserved. 30 Outline getquery.cpp (3 of 4)
31
2006 Pearson Education, Inc. All rights reserved. 31 Outline getquery.cpp (4 of 4)
32
2006 Pearson Education, Inc. All rights reserved. 32 Outline post.cpp (1 of 5)
33
2006 Pearson Education, Inc. All rights reserved. 33 Outline post.cpp (2 of 5)
34
2006 Pearson Education, Inc. All rights reserved. 34 Outline post.cpp (3 of 5)
35
2006 Pearson Education, Inc. All rights reserved. 35 Outline post.cpp (4 of 5)
36
2006 Pearson Education, Inc. All rights reserved. 36 Outline post.cpp (5 of 5)
37
2006 Pearson Education, Inc. All rights reserved. 37 Outline travel.html (1 of 2)
38
2006 Pearson Education, Inc. All rights reserved. 38 Outline travel.html (2 of 2)
39
2006 Pearson Education, Inc. All rights reserved. 39 Outline portal.cpp (1 of 5)
40
2006 Pearson Education, Inc. All rights reserved. 40 Outline portal.cpp (2 of 5)
41
2006 Pearson Education, Inc. All rights reserved. 41 Outline portal.cpp (3 of 5)
42
2006 Pearson Education, Inc. All rights reserved. 42 Outline portal.cpp (4 of 5)
43
2006 Pearson Education, Inc. All rights reserved. 43 Outline portal.cpp (5 of 5)
44
2006 Pearson Education, Inc. All rights reserved. 44 Performance Tip 19.1 It is always much more efficient for the server to provide static content rather than execute a CGI script, because it takes time for the server to load the script from hard disk into memory and execute the script (whereas an XHTML file needs to be sent only to the client). It is a good practice to use a mix of static XHTML (for content that generally remains unchanged) and CGI scripting (for dynamic content). This practice allows the Web server to respond to clients more efficiently than if only CGI scripting were used.
45
2006 Pearson Education, Inc. All rights reserved. 45 Outline cookieform.html (1 of 2)
46
2006 Pearson Education, Inc. All rights reserved. 46 Outline cookieform.html (2 of 2)
47
2006 Pearson Education, Inc. All rights reserved. 47 Outline writecookie.cpp (1 of 4)
48
2006 Pearson Education, Inc. All rights reserved. 48 Outline writecookie.cpp (2 of 4)
49
2006 Pearson Education, Inc. All rights reserved. 49 Outline writecookie.cpp (3 of 4)
50
2006 Pearson Education, Inc. All rights reserved. 50 Outline writecookie.cpp (4 of 4)
51
2006 Pearson Education, Inc. All rights reserved. 51 Portability Tip 19.1 Web browsers store the cookie information in a vendor-specific manner. For example, Microsoft’s Internet Explorer stores cookies as text files in the Temporary Internet Files directory on the client’s machine. Netscape stores its cookies in a single file named cookies.txt.
52
2006 Pearson Education, Inc. All rights reserved. 52 Outline readcookie.cpp (1 of 3)
53
2006 Pearson Education, Inc. All rights reserved. 53 Outline readcookie.cpp (2 of 3)
54
2006 Pearson Education, Inc. All rights reserved. 54 Outline readcookie.cpp (3 of 3)
55
2006 Pearson Education, Inc. All rights reserved. 55 Software Engineering Observation 19.2 Cookies present a security risk. If unauthorized users gain access to a computer, they can examine the local disk and view files, which include cookies. For this reason, sensitive data, such as passwords, social security numbers and credit card numbers, should never be stored in cookies.
56
2006 Pearson Education, Inc. All rights reserved. 56 Outline savefile.html (1 of 2)
57
2006 Pearson Education, Inc. All rights reserved. 57 Outline savefile.html (2 of 2)
58
2006 Pearson Education, Inc. All rights reserved. 58 Outline savefile.cpp (1 of 6)
59
2006 Pearson Education, Inc. All rights reserved. 59 Outline savefile.cpp (2 of 6)
60
2006 Pearson Education, Inc. All rights reserved. 60 Outline savefile.cpp (3 of 6)
61
2006 Pearson Education, Inc. All rights reserved. 61 Outline savefile.cpp (4 of 6)
62
2006 Pearson Education, Inc. All rights reserved. 62 Outline savefile.cpp (5 of 6)
63
2006 Pearson Education, Inc. All rights reserved. 63 Outline savefile.cpp (6 of 6)
64
2006 Pearson Education, Inc. All rights reserved. 64 Fig. 19.20 | Contents of clients.txt data file.
65
2006 Pearson Education, Inc. All rights reserved. 65 Outline login.cpp (1 of 11)
66
2006 Pearson Education, Inc. All rights reserved. 66 Outline login.cpp (2 of 11)
67
2006 Pearson Education, Inc. All rights reserved. 67 Outline login.cpp (3 of 11)
68
2006 Pearson Education, Inc. All rights reserved. 68 Outline login.cpp (4 of 11)
69
2006 Pearson Education, Inc. All rights reserved. 69 Outline login.cpp (5 of 11)
70
2006 Pearson Education, Inc. All rights reserved. 70 Outline login.cpp (6 of 11)
71
2006 Pearson Education, Inc. All rights reserved. 71 Outline login.cpp (7 of 11)
72
2006 Pearson Education, Inc. All rights reserved. 72 Outline login.cpp (8 of 11)
73
2006 Pearson Education, Inc. All rights reserved. 73 Outline login.cpp (9 of 11)
74
2006 Pearson Education, Inc. All rights reserved. 74 Outline login.cpp (10 of 11)
75
2006 Pearson Education, Inc. All rights reserved. 75 Outline login.cpp (11 of 11)
76
2006 Pearson Education, Inc. All rights reserved. 76 Outline shop.cpp (1 of 5)
77
2006 Pearson Education, Inc. All rights reserved. 77 Outline shop.cpp (2 of 5)
78
2006 Pearson Education, Inc. All rights reserved. 78 Outline shop.cpp (3 of 5)
79
2006 Pearson Education, Inc. All rights reserved. 79 Outline shop.cpp (4 of 5)
80
2006 Pearson Education, Inc. All rights reserved. 80 Outline shop.cpp (5 of 5)
81
2006 Pearson Education, Inc. All rights reserved. 81 Outline viewcart.cpp (1 of 7)
82
2006 Pearson Education, Inc. All rights reserved. 82 Outline viewcart.cpp (2 of 7)
83
2006 Pearson Education, Inc. All rights reserved. 83 Outline viewcart.cpp (3 of 7)
84
2006 Pearson Education, Inc. All rights reserved. 84 Outline viewcart.cpp (4 of 7)
85
2006 Pearson Education, Inc. All rights reserved. 85 Outline viewcart.cpp (5 of 7)
86
2006 Pearson Education, Inc. All rights reserved. 86 Outline viewcart.cpp (6 of 7)
87
2006 Pearson Education, Inc. All rights reserved. 87 Outline viewcart.cpp (7 of 7)
88
2006 Pearson Education, Inc. All rights reserved. 88 Outline checkout.cpp (1 of 2)
89
2006 Pearson Education, Inc. All rights reserved. 89 Outline checkout.cpp (2 of 2)
90
2006 Pearson Education, Inc. All rights reserved. 90 Fig. 19.25 | Contents of catalog.txt.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.