Internet Applications 1 Lecture Overview Internet Concepts Data

  • Slides: 54
Download presentation
Internet Applications 1

Internet Applications 1

Lecture Overview Internet Concepts: Data Flow from Client to DBMS v Introduction to three-tier

Lecture Overview Internet Concepts: Data Flow from Client to DBMS v Introduction to three-tier architectures v Web data formats v § HTML, XML v The presentation layer § HTML forms; Javascript; Stylesheets v The middle tier § CGI, application servers, passing arguments, maintaining state (cookies) 2

Components of Data-Intensive Systems Three separate types of functionality: v Data management v Application

Components of Data-Intensive Systems Three separate types of functionality: v Data management v Application logic v Presentation v The system architecture determines whether these three components reside on a single system (“tier) or are distributed across several tiers 3

Process/Data Flow in Network Enters request User/Client Application Returns results Sends query Database Returns

Process/Data Flow in Network Enters request User/Client Application Returns results Sends query Database Returns data 4

Example: Course Enrolment Enters request: add course, drop course User/Client Sends query: Course availability,

Example: Course Enrolment Enters request: add course, drop course User/Client Sends query: Course availability, student info, … Application • Checks constraints • returns confirmation for display Database Returns data 5

Example: Airline Reservation System Enters request: log in, show seat map User/Client Sends query:

Example: Airline Reservation System Enters request: log in, show seat map User/Client Sends query: Airline info, available seats, customer info… Application Returns results: map data for display, confirmation Database Returns data 6

Example: Book Order System • Sends query: List books, customer info, … • maintains

Example: Book Order System • Sends query: List books, customer info, … • maintains shopping cart Enters request: search for book User/Client Application Returns results: requested data, recommendations, order information. Database Returns data 7

Architecture Overview 8

Architecture Overview 8

Client-Server Architectures Work division: Thin client § Client implements only the graphical user interface

Client-Server Architectures Work division: Thin client § Client implements only the graphical user interface § Server implements business logic and data management. § Development supported by Visual Studio, Sybase Powerbuilder. v Work division: Thick client § Client implements both the graphical user interface and the business logic § Server implements data management 9

Examples v Thick Client § Video game console v Thin Client § streaming services:

Examples v Thick Client § Video game console v Thin Client § streaming services: netflix, spotify 10

Discussion Question v What are advantages of thin clients? v What are disadvantages of

Discussion Question v What are advantages of thin clients? v What are disadvantages of thin clients? v What are advantages of thick clients? v What are disadvantages of thick clients? 11

Client-Server Architectures Disadvantages of thick clients § No central place to update the business

Client-Server Architectures Disadvantages of thick clients § No central place to update the business logic § Security issues: Server needs to trust clients • Access control and authentication needs to be managed at the server • Clients need to leave server database in consistent state § Does not scale to more than several 100 s of clients • Large data transfer between server and client • More than one server creates a problem: x clients, y servers: x*y connections 12

The Three-Tier Architecture Presentation tier Middle tier Data management tier Client Program (Web Browser)

The Three-Tier Architecture Presentation tier Middle tier Data management tier Client Program (Web Browser) Application Server Database System C l o u d 13

The Three Layers Presentation tier § Primary interface to the user § Needs to

The Three Layers Presentation tier § Primary interface to the user § Needs to adapt to different display devices (PC, PDA, cell phone, voice access? ) Middle tier § Implements business logic (implements complex actions, maintains state between different steps of a workflow) § Accesses different data management systems Data management tier § Standard database management systems 14

Example 1: Airline reservations Build a system for making airline reservations v What is

Example 1: Airline reservations Build a system for making airline reservations v What is done in the different tiers? v Database System v § Airline info, available seats, customer info, etc. v Application Server § Logic to make reservations, cancel reservations, add new airlines, etc. v Client Program § Log in different users, display forms and humanreadable output 15

Example 2: Course Enrollment Build a system for students to enroll in courses v

Example 2: Course Enrollment Build a system for students to enroll in courses v Database System v § Student info, course info, instructor info, course availability, pre-requisites, etc. v Application Server § Logic to add a course, drop a course, create a new course, etc. v Client Program § Log in different users (students, staff, faculty), display forms and human-readable output 16

Advantages of the Three-Tier Architecture v v v Heterogeneous systems § Tiers can be

Advantages of the Three-Tier Architecture v v v Heterogeneous systems § Tiers can be independently maintained, modified, and replaced Thin clients § Only presentation layer at clients (web browsers) Integrated data access § Several database systems can be handled transparently at the middle tier § Central management of connections Scalability § Replication at middle tier permits scalability of business logic Software development § Code for business logic is centralized § Interaction between tiers through well-defined APIs: Can reuse standard components at each tier 17

Discussion Question Do mobile devices follow the 3 -tier architecture? v If not, does

Discussion Question Do mobile devices follow the 3 -tier architecture? v If not, does this cause problems? v 18

Technologies Client Program (Web Browser) Application Server (Tomcat, Apache) Database System (DB 2, SQL

Technologies Client Program (Web Browser) Application Server (Tomcat, Apache) Database System (DB 2, SQL Server) HTML Javascript JSP Servlets Cookies CGI XML Stored Procedures 19

Presentation Layer HTTP 20

Presentation Layer HTTP 20

Multiple Choice Question HTML 1. is a language for programming web browsers 2. refers

Multiple Choice Question HTML 1. is a language for programming web browsers 2. refers to the hypertext transfer protocol 3. is a language for making web pages 4. communicates data from the client to the database. Choose one. 21

Overview of the Presentation Tier v Functionality of the presentation tier § Primary interface

Overview of the Presentation Tier v Functionality of the presentation tier § Primary interface to the user § Needs to adapt to different display devices (PC, PDA, cell phone, voice access? ) § Simple functionality, such as field validity checking v We will cover: § Http protocol. § XML, HTML Forms: How to pass data to the middle tier § Java. Script: Simple functionality at the presentation tier. 22

Web Data Formats v HTML § The presentation language for the Internet v XML

Web Data Formats v HTML § The presentation language for the Internet v XML § A self-describing, hierarchical data model. § XML Examples and Exercises v And others, e. g. SGML, not covered. 23

Uniform Resource Identifiers v v Uniform naming schema to identify resources on the Internet

Uniform Resource Identifiers v v Uniform naming schema to identify resources on the Internet A resource can be anything: § Index. html § mysong. mp 3 § picture. jpg v Example URIs: http: //www. cs. wisc. edu/~dbbook/index. html mailto: webmaster@bookstore. com 24

Structure of URIs http: //www. cs. wisc. edu/~dbbook/index. html v URI has three parts:

Structure of URIs http: //www. cs. wisc. edu/~dbbook/index. html v URI has three parts: § Naming schema (http) § Name of the host computer (www. cs. wisc. edu) § Name of the resource (~dbbook/index. html) v URLs are a subset of URIs 25

Hypertext Transfer Protocol v What is a communication protocol? § § Set of standards

Hypertext Transfer Protocol v What is a communication protocol? § § Set of standards that defines the structure of messages Examples: TCP, IP, HTTP v What happens if you click on www. cs. wisc. edu/~dbbook/index. html? 1. Client (web browser) sends HTTP request to server Server receives request and replies Client receives reply; makes new requests 2. 3. 26

HTTP (Contd. ) Client to Server: Server replies: GET ~/index. html HTTP/1. 1 User-agent:

HTTP (Contd. ) Client to Server: Server replies: GET ~/index. html HTTP/1. 1 User-agent: Mozilla/4. 0 Accept: text/html, image/gif, image/jpeg HTTP/1. 1 200 OK Date: Mon, 04 Mar 2002 12: 00 GMT Server: Apache/1. 3. 0 (Linux) Last-Modified: Mon, 01 Mar 2002 09: 23: 24 GMT Content-Length: 1024 Content-Type: text/html <HTML> <HEAD></HEAD> <BODY> <h 1>Barns and Nobble Internet Bookstore</h 1> Our inventory: <h 3>Science</h 3> <b>The Character of Physical Law</b>. . . 27

HTTP Protocol Structure HTTP Requests v Request line: GET ~/index. html HTTP/1. 1 §

HTTP Protocol Structure HTTP Requests v Request line: GET ~/index. html HTTP/1. 1 § GET: Http method field (possible values are GET and POST, more later) § ~/index. html: URI field § HTTP/1. 1: HTTP version field v v Type of client: User-agent: Mozilla/4. 0 What types of files will the client accept: Accept: text/html, image/gif, image/jpeg 28

HTTP Protocol Structure (Contd. ) HTTP Responses v Status line: HTTP/1. 1 200 OK

HTTP Protocol Structure (Contd. ) HTTP Responses v Status line: HTTP/1. 1 200 OK § § HTTP version: HTTP/1. 1 Status code: 200 Server message: OK Common status code/server message combinations: • • v v 200 OK: Request succeeded 400 Bad Request: Request could not be fulfilled by the server 404 Not Found: Requested object does not exist on the server 505 HTTP Version not Supported Date when the object was created: Last-Modified: Mon, 01 Mar 2002 09: 23: 24 GMT Number of bytes being sent: Content-Length: 1024 What type is the object being sent: Content-Type: text/html Other information such as the server type, server time, etc. 29

HTTP has no states v HTTP is stateless § No sessions § Every message

HTTP has no states v HTTP is stateless § No sessions § Every message is completely selfcontained § No previous interaction is remembered by the protocol – fire and forget. 30

Hypertext Markup Language HTML 31

Hypertext Markup Language HTML 31

HTML: An Example <HTML> <HEAD></HEAD> <BODY> <h 1>Barns and Nobble Internet Bookstore</h 1> Our

HTML: An Example <HTML> <HEAD></HEAD> <BODY> <h 1>Barns and Nobble Internet Bookstore</h 1> Our inventory: <h 3>Science</h 3> <b>The Character of Physical Law<b> <UL> <LI>Author: Richard Feynman</LI> <LI>Published 1980</LI> <LI>Hardcover</LI> </UL> <h 3>Fiction</h 3> <b>Waiting for the Mahatma</b> <UL> <LI>Author: R. K. Narayan</LI> <LI>Published 1981</LI> </UL> <b>The English Teacher</b> <UL> <LI>Author: R. K. Narayan</LI> <LI>Published 1980</LI> <LI>Paperback</LI> </UL> </BODY> </HTML> 32

HTML: A Short Introduction HTML is a markup language: for presentation. v Commands are

HTML: A Short Introduction HTML is a markup language: for presentation. v Commands are tags: v § Start tag and end tag § Examples: • <HTML> … </HTML> • <UL> … </UL> v Many editors automatically generate HTML directly from your document. 33

HTML: Sample Commands <HTML>: v <UL>: unordered list v <LI>: list entry v <h

HTML: Sample Commands <HTML>: v <UL>: unordered list v <LI>: list entry v <h 1>: largest heading v <h 2>: second-level heading, <h 3>, <h 4> analogous v <B>Title</B>: Bold v 34

HTML Forms v v Common way to communicate data from client to middle tier

HTML Forms v v Common way to communicate data from client to middle tier General format of a form: § <FORM ACTION=“page. jsp” METHOD=“GET” NAME=“Login. Form”> … </FORM> v Components of an HTML FORM tag: § ACTION: Specifies URI that handles the content § METHOD: Specifies HTTP GET or POST method § NAME: Name of the form; can be used in client-side scripts to refer to the form 35

Inside HTML Forms v INPUT tag § Attributes: • TYPE: text (text input field),

Inside HTML Forms v INPUT tag § Attributes: • TYPE: text (text input field), password (text input field where input is, reset (resets all input fields) • NAME: symbolic name, used to identify field value at the middle tier • VALUE: default value § Example: <INPUT TYPE=“text” Name=“title”> v Example form: <form method="POST" action="Table. Of. Contents. jsp"> <input type="text" name="userid"> <input type="password" name="password"> <input type="submit" value="Login“ name="submit"> <input type=“reset” value=“Clear”> </form> 36

Passing Arguments Two methods: GET and POST v GET: Form contents go into URI

Passing Arguments Two methods: GET and POST v GET: Form contents go into URI v Structure: action? name 1=value 1&name 2=value 2&name 3=value 3 v Action: name of the URI specified in the form v (name, value)-pairs come from INPUT fields in the form; empty fields have empty values (“name=“) v Example from previous password form: Table. Of. Contents. jsp? userid=john&password=johnpw v Action needs to refer to a program, script, or page that will process the user input 37

HTML Forms: A Complete Example <form method="POST" action="Table. Of. Contents. jsp”> <table align =

HTML Forms: A Complete Example <form method="POST" action="Table. Of. Contents. jsp”> <table align = "center" border="0" width="300”> <tr> <td>Userid</td> <td><input type="text" name="userid" VALUE="wisnesky" size="20"></td> </tr> <td>Password</td> <td><input type="password" name="password" size="20"></td> </tr> <td>Login</td> <td align = "left"> <input type="text" name="submit" size="20"></td> </tr> <td><input type="submit"></td> <td><input type="reset"></td> </tr> </table></form> 38

Java. Script v v Goal: Add functionality to the presentation tier. Sample applications: §

Java. Script v v Goal: Add functionality to the presentation tier. Sample applications: § Detect browser type and load browser-specific page § Form validation: Validate form input fields § Browser control: Open new windows, close existing windows (example: pop-up ads) v v Usually embedded directly inside the HTML with the <SCRIPT> … </SCRIPT> tag. <SCRIPT> tag has several attributes: § LANGUAGE: specifies language of the script (such as javascript) § SRC: external file with script code § Example: <SCRIPT LANGUAGE=“Java. Script” SRC=“validate. js> </SCRIPT> 39

Java. Script (Contd. ) v Java. Script is a complete scripting language § Variables

Java. Script (Contd. ) v Java. Script is a complete scripting language § Variables § Assignments (=, +=, …) § Comparison operators (<, >, …), boolean operators (&&, ||, !) § Statements • if (condition) {statements; } else {statements; } • for loops, do-while loops, and while-loops § Functions with return values • Create functions using the function keyword • f(arg 1, …, argk) {statements; } 40

Java. Script: A Complete Example HTML Form: Associated Java. Script: <form method="POST“ action="Table. Of.

Java. Script: A Complete Example HTML Form: Associated Java. Script: <form method="POST“ action="Table. Of. Contents. jsp” name=“Login. Form”> <input type="text" name="userid"> <input type="password" name="password"> <input type="submit" value="Login“ name="submit"> <input type=“reset” value=“Clear”> </form> <script language="javascript"> function test. Login. Empty() { login. Form = document. Login. Form if ((login. Form. userid. value == "") || (login. Form. password. value == "")) { alert('Please enter values for userid and password. '); return false; } else return true; } </script> 41

Application Logic MIDDLE LAYER 42

Application Logic MIDDLE LAYER 42

Overview of the Middle Tier v v Functionality of the middle tier § Encodes

Overview of the Middle Tier v v Functionality of the middle tier § Encodes business logic § Connects to database system(s) § Accepts form input from the presentation tier § Generates output for the presentation tier CGI: Protocol for passing arguments to programs running at the middle tier Application servers: Runtime environment at the middle tier v Maintaining state: How to maintain state at the middle tier. Main focus: Cookies. v 43

Application Servers Main pool of threads inside processes. v Requests are assigned to threads

Application Servers Main pool of threads inside processes. v Requests are assigned to threads (cheap) rather than separate processes. v Manage connections v Enable access to heterogeneous data sources v Other functionality such as APIs for session management. v Servlets handle client requests using Java. v 45

Application Server: Process Structure Web Browser HTTP Web Server PHP et al. C++ Application

Application Server: Process Structure Web Browser HTTP Web Server PHP et al. C++ Application Java. Beans Application Server JDBC ODBC DBMS 1 DBMS 2 Pool of Servlets 46

So many kinds of state… …how will I choose? APPLICATION STATE 47

So many kinds of state… …how will I choose? APPLICATION STATE 47

Maintaining State HTTP is stateless. v Advantages § Easy to use: don’t need memory

Maintaining State HTTP is stateless. v Advantages § Easy to use: don’t need memory management. § Great for static-information applications (“fire and forget”) § Requires no extra memory space v Disadvantages § No record of previous requests means • • No shopping baskets No user logins No custom or dynamic content Security is more difficult to implement 48

Server-Side State Many types of Server side state: 1. Store information in a database

Server-Side State Many types of Server side state: 1. Store information in a database § Data will be safe in the database § BUT: requires a database access to query or update the information 2. Use application layer’s local memory § Can map the user’s IP address to some state § BUT: this information is volatile and takes up lots of server main memory 5 million IPs = 20 MB 49

Server-Side State v Should use Server-side state maintenance for information that needs to persist

Server-Side State v Should use Server-side state maintenance for information that needs to persist § Old customer orders § “Click trails” of a user’s movement through a site § Permanent choices a user makes 50

Client-side State: Cookies v Storing text on the client which will be passed to

Client-side State: Cookies v Storing text on the client which will be passed to the application with every HTTP request. § Can be disabled by the client. § Are perceived as "dangerous”. § May scare away site visitors if asked to enable cookies Are a collection of (Name, Value) pairs. v Discussion Question: what do you think of cookies? v 51

Client State: Cookies v v v Advantages § Easy to use in Java Servlets

Client State: Cookies v v v Advantages § Easy to use in Java Servlets / JSP § Provide a simple way to keep non-essential data on the client side even when the browser has closed Disadvantages § Limit of 4 kilobytes of information § Users can (and often will) disable them Should use cookies to store interactive state § The current user’s login information § The current shopping basket § Any non-permanent choices the user has made 52

Cookie Features v Cookies can have § A duration (expire right away or persist

Cookie Features v Cookies can have § A duration (expire right away or persist even after the browser has closed) § Filters for which domains/directory paths the cookie is sent to. 53

Multiple state methods v Typically all methods of state maintenance are used: § User

Multiple state methods v Typically all methods of state maintenance are used: § User logs in and this information is stored in a cookie § User issues a query which is stored in the URL. § User places an item in a shopping basket cookie § User purchases items and credit-card information is stored/retrieved from a database § User leaves a click-stream which is kept in a log on the web server. 54

Summary We covered: v Internet Concepts (URIs, HTTP) v Web data formats § HTML,

Summary We covered: v Internet Concepts (URIs, HTTP) v Web data formats § HTML, XML v Three-tier architecture. v The presentation layer § HTML forms; HTTP Get and POST, URL encoding; Javascript. v The middle tier § CGI, application servers, Servlets, passing arguments, maintaining state (cookies). v Only lecture material will be on exam (not other material from Ch. 7). 55