Top Banner
40

n Application Programs and User Interfaces · n The Web is a distributed information system based on hypertext. n Most Web documents are hypertext documents formatted via the HyperText

Aug 06, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: n Application Programs and User Interfaces · n The Web is a distributed information system based on hypertext. n Most Web documents are hypertext documents formatted via the HyperText
Page 2: n Application Programs and User Interfaces · n The Web is a distributed information system based on hypertext. n Most Web documents are hypertext documents formatted via the HyperText

n Application Programs and User Interfacesn Web Fundamentalsn Servlets and JSPn Application Architecturesn Rapid Application Developmentn Application Performancen Application Securityn Encryption and Its Applications

Page 3: n Application Programs and User Interfaces · n The Web is a distributed information system based on hypertext. n Most Web documents are hypertext documents formatted via the HyperText

n Most database users do not use a query language like SQL

n An application program acts as the intermediary between users and the databasel Applications split into4front-end4middle layer4backend

n Front-end: user interfacel Formsl Graphical user interfacesl Many interfaces are Web-based

Page 4: n Application Programs and User Interfaces · n The Web is a distributed information system based on hypertext. n Most Web documents are hypertext documents formatted via the HyperText

Application Architecture Evolution

n Three distinct era’s of application architecturel mainframe (1960’s and 70’s)l personal computer era (1980’s)l We era (1990’s onwards)

Page 5: n Application Programs and User Interfaces · n The Web is a distributed information system based on hypertext. n Most Web documents are hypertext documents formatted via the HyperText

Web Interfacen Web browsers have become the de-facto standard user

interface to databasesl Enable large numbers of users to access databases

from anywherel Avoid the need for downloading/installing specialized

code, while providing a good graphical user interface4 Javascript, Flash and other scripting languages run

in browser, but are downloaded transparentlyl Examples: banks, airline and rental car reservations,

university course registration and grading, an so on.

Page 6: n Application Programs and User Interfaces · n The Web is a distributed information system based on hypertext. n Most Web documents are hypertext documents formatted via the HyperText

n The Web is a distributed information system based on hypertext.

n Most Web documents are hypertext documents formatted via the HyperText Markup Language (HTML)

n HTML documents containl text along with font specifications, and other

formatting instructionsl hypertext links to other documents, which can be

associated with regions of the text.l forms, enabling users to enter data which can then

be sent back to the Web server

Page 7: n Application Programs and User Interfaces · n The Web is a distributed information system based on hypertext. n Most Web documents are hypertext documents formatted via the HyperText

n In the Web, functionality of pointers is provided by Uniform Resource Locators (URLs).

n URL example: http://www.acm.org/sigmod l The first part indicates how the document is to be accessed

4 “http” indicates that the document is to be accessed using the Hyper Text Transfer Protocol.

l The second part gives the unique name of a machine on the Internet.l The rest of the URL identifies the document within the machine.

n The local identification can be:4The path name of a file on the machine, or4An identifier (path name) of a program, plus arguments to be

passed to the program– E.g., http://www.google.com/search?q=silberschatz

Page 8: n Application Programs and User Interfaces · n The Web is a distributed information system based on hypertext. n Most Web documents are hypertext documents formatted via the HyperText

n HTML provides formatting, hypertext link, and image display featuresl including tables, stylesheets (to alter default formatting),

etc.n HTML also provides input features

4Select from a set of options– Pop-up menus, radio buttons, check lists

4Enter values– Text boxes

l Filled in input sent back to the server, to be acted upon by an executable at the server

n HyperText Transfer Protocol (HTTP) used for communication with the Web server

Page 9: n Application Programs and User Interfaces · n The Web is a distributed information system based on hypertext. n Most Web documents are hypertext documents formatted via the HyperText

<html><body> <table border>

<tr> <th>ID</th> <th>Name</th> <th>Department</th> </tr><tr> <td>00128</td> <td>Zhang</td> <td>Comp. Sci.</td> </tr>….

</table> <form action="PersonQuery" method=get>

Search for: <select name="persontype"> <option value="student" selected>Student </option> <option value="instructor"> Instructor </option> </select> <br>Name: <input type=text size=20 name="name"><input type=submit value="submit">

</form></body> </html>

Page 10: n Application Programs and User Interfaces · n The Web is a distributed information system based on hypertext. n Most Web documents are hypertext documents formatted via the HyperText
Page 11: n Application Programs and User Interfaces · n The Web is a distributed information system based on hypertext. n Most Web documents are hypertext documents formatted via the HyperText

n A Web server can easily serve as a front end to a variety of information services.

n The document name in a URL may identify an executable program, that, when run, generates a HTML document.l When an HTTP server receives a request for such a

document, it executes the program, and sends back the HTML document that is generated.

l The Web client can pass extra arguments with the name of the document.

n To install a new service on the Web, one simply needs to create and install an executable that provides that service.l The Web browser provides a graphical user interface to the

information service.n Common Gateway Interface (CGI): a standard interface

between web and application server

Page 12: n Application Programs and User Interfaces · n The Web is a distributed information system based on hypertext. n Most Web documents are hypertext documents formatted via the HyperText
Page 13: n Application Programs and User Interfaces · n The Web is a distributed information system based on hypertext. n Most Web documents are hypertext documents formatted via the HyperText

n Multiple levels of indirection have overheadsAlternative: two-layer architecture

Page 14: n Application Programs and User Interfaces · n The Web is a distributed information system based on hypertext. n Most Web documents are hypertext documents formatted via the HyperText

n The HTTP protocol is connectionlessl That is, once the server replies to a request, the server closes the

connection with the client, and forgets all about the requestl In contrast, Unix logins, and JDBC/ODBC connections stay

connected until the client disconnects4 retaining user authentication and other information

l Motivation: reduces load on server 4operating systems have tight limits on number of open

connections on a machinen Information services need session information

l E.g., user authentication should be done only once per sessionn Solution: use a cookie

Page 15: n Application Programs and User Interfaces · n The Web is a distributed information system based on hypertext. n Most Web documents are hypertext documents formatted via the HyperText

n A cookie is a small piece of text containing identifying informationl Sent by server to browser 4Sent on first interaction, to identify session

l Sent by browser to the server that created the cookie on further interactions4part of the HTTP protocol

l Server saves information about cookies it issued, and can use it when serving a request4E.g., authentication information, and user

preferencesn Cookies can be stored permanently or for a limited time

Page 16: n Application Programs and User Interfaces · n The Web is a distributed information system based on hypertext. n Most Web documents are hypertext documents formatted via the HyperText

n Java Servlet specification defines an API for communication between the Web/application server and application program running in the serverl E.g., methods to get parameter values from

Web forms, and to send HTML text back to client

n Application program (also called a servlet) is loaded into the serverl Each request spawns a new thread in the

server4 thread is closed once the request is serviced

Page 17: n Application Programs and User Interfaces · n The Web is a distributed information system based on hypertext. n Most Web documents are hypertext documents formatted via the HyperText

import java.io.*;import javax.servlet.*;import javax.servlet.http.*;public class PersonQueryServlet extends HttpServlet { public void doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println("<HEAD><TITLE> Query Result</TITLE></HEAD>"); out.println("<BODY>"); ….. BODY OF SERVLET (next slide) … out.println("</BODY>"); out.close(); }}

Page 18: n Application Programs and User Interfaces · n The Web is a distributed information system based on hypertext. n Most Web documents are hypertext documents formatted via the HyperText

String persontype = request.getParameter("persontype");String number = request.getParameter("name");if(persontype.equals("student")) { ... code to find students with the specified name ... ... using JDBC to communicate with the database .. out.println("<table BORDER COLS=3>"); out.println(" <tr> <td>ID</td> <td>Name: </td>" + " <td>Department</td> </tr>"); for(... each result ...){ ... retrieve ID, name and dept name ... into variables ID, name and deptname out.println("<tr> <td>" + ID + "</td>" + "<td>" + name + "</td>" + "<td>" + deptname

+ "</td></tr>"); }; out.println("</table>");}else { ... as above, but for instructors ...}

Page 19: n Application Programs and User Interfaces · n The Web is a distributed information system based on hypertext. n Most Web documents are hypertext documents formatted via the HyperText

n Servlet API supports handling of sessionsl Sets a cookie on first interaction with browser, and uses it to

identify session on further interactionsn To check if session is already active:

l if (request.getSession(false) == true)4 .. then existing session4else .. redirect to authentication page

l authentication page4check login/password4 request.getSession(true): creates new session

n Store/retrieve attribute value pairs for a particular sessionl session.setAttribute(“userid”, userid)l session.getAttribute(“userid”)

Page 20: n Application Programs and User Interfaces · n The Web is a distributed information system based on hypertext. n Most Web documents are hypertext documents formatted via the HyperText

Servlet Support

n Servlets run inside application servers such as l Apache Tomcat, Glassfish, JBossl BEA Weblogic, IBM WebSphere and Oracle

Application Serversn Application servers support l deployment and monitoring of servletsl Java 2 Enterprise Edition (J2EE) platform

supporting objects, parallel processing across multiple application servers, etc

Page 21: n Application Programs and User Interfaces · n The Web is a distributed information system based on hypertext. n Most Web documents are hypertext documents formatted via the HyperText

n Server-side scripting simplifies the task of connecting a database to the Webl Define an HTML document with embedded

executable code/SQL queries.l Input values from HTML forms can be used directly in

the embedded code/SQL queries.l When the document is requested, the Web server

executes the embedded code/SQL queries to generate the actual HTML document.

n Numerous server-side scripting languagesl JSP, PHPl General purpose scripting languages: VBScript, Perl,

Python

Page 22: n Application Programs and User Interfaces · n The Web is a distributed information system based on hypertext. n Most Web documents are hypertext documents formatted via the HyperText

n A JSP page with embedded Java code<html><head> <title> Hello </title> </head><body><% if (request.getParameter(“name”) == null){ out.println(“Hello World”); }else { out.println(“Hello, ” + request.getParameter(“name”)); }%></body></html>

n JSP is compiled into Java + Servletsn JSP allows new tags to be defined, in tag libraries

l such tags are like library functions, can are used for example to build rich user interfaces such as paginated display of large datasets

Page 23: n Application Programs and User Interfaces · n The Web is a distributed information system based on hypertext. n Most Web documents are hypertext documents formatted via the HyperText

PHP

n PHP is widely used for Web server scriptingn Extensive libaries including for database access using ODBC <html>

<head> <title> Hello </title> </head><body><?php if (!isset($_REQUEST[‘name’])){ echo “Hello World”; }else { echo “Hello, ” + $_REQUEST[‘name’]; }?></body></html>

Page 24: n Application Programs and User Interfaces · n The Web is a distributed information system based on hypertext. n Most Web documents are hypertext documents formatted via the HyperText

n Browsers can fetch certain scripts (client-side scripts) or programs along with documents, and execute them in “safe mode” at the client sitel Javascriptl Macromedia Flash and Shockwave for animation/gamesl VRMLl Applets

n Client-side scripts/programs allow documents to be activel E.g., animation by executing programs at the local sitel E.g., ensure that values entered by users satisfy some

correctness checksl Permit flexible interaction with the user.

4 Executing programs at the client site speeds up interaction by avoiding many round trips to server

Page 25: n Application Programs and User Interfaces · n The Web is a distributed information system based on hypertext. n Most Web documents are hypertext documents formatted via the HyperText

n Security mechanisms needed to ensure that malicious scripts do not cause damage to the client machinel Easy for limited capability scripting languages, harder for

general purpose programming languages like Javan E.g., Java’s security system ensures that the Java applet

code does not make any system calls directlyl Disallows dangerous actions such as file writesl Notifies the user about potentially dangerous actions, and

allows the option to abort the program or to continue execution.

Page 26: n Application Programs and User Interfaces · n The Web is a distributed information system based on hypertext. n Most Web documents are hypertext documents formatted via the HyperText

Javascript

n Javascript very widely usedl forms basis of new generation of Web applications (called Web

2.0 applications) offering rich user interfacesn Javascript functions can

l check input for validityl modify the displayed Web page, by altering the underling

document object model (DOM) tree representation of the displayed HTML text

l communicate with a Web server to fetch data and modify the current page using fetched data, without needing to reload/refresh the page4 forms basis of AJAX technology used widely in Web 2.0

applications4 E.g. on selecting a country in a drop-down menu, the list of

states in that country is automatically populated in a linked drop-down menu

Page 27: n Application Programs and User Interfaces · n The Web is a distributed information system based on hypertext. n Most Web documents are hypertext documents formatted via the HyperText

Javascript

n Example of Javascript used to validate form input<html> <head>

<script type="text/javascript"> function validate() { var credits=document.getElementById("credits").value; if (isNaN(credits)|| credits<=0 || credits>=16) { alert("Credits must be a number greater than 0 and less than 16"); return false } }</script>

</head> <body><form action="createCourse" onsubmit="return validate()"> Title: <input type="text" id="title" size="20"><br /> Credits: <input type="text" id="credits" size="2"><br /> <Input type="submit" value="Submit"></form>

</body> </html>

Page 28: n Application Programs and User Interfaces · n The Web is a distributed information system based on hypertext. n Most Web documents are hypertext documents formatted via the HyperText

Application Architectures

Page 29: n Application Programs and User Interfaces · n The Web is a distributed information system based on hypertext. n Most Web documents are hypertext documents formatted via the HyperText

Application Architectures

n Application layersl Presentation or user interface

4model-view-controller (MVC) architecture– model: business logic– view: presentation of data, depends on display device– controller: receives events, executes actions, and returns a view

to the userl business-logic layer

4 provides high level view of data and actions on data– often using an object data model

4 hides details of data storage schemal data access layer

4 interfaces between business logic layer and the underlying database4 provides mapping from object model of business layer to relational

model of database

Page 30: n Application Programs and User Interfaces · n The Web is a distributed information system based on hypertext. n Most Web documents are hypertext documents formatted via the HyperText

Application Architecture

Page 31: n Application Programs and User Interfaces · n The Web is a distributed information system based on hypertext. n Most Web documents are hypertext documents formatted via the HyperText

Business Logic Layer

n Provides abstractions of entitiesl e.g. students, instructors, courses, etc

n Enforces business rules for carrying out actionsl E.g. student can enroll in a class only if she has completed

prerequsites, and has paid her tuition feesn Supports workflows which define how a task involving multiple

participants is to be carried outl E.g. how to process application by a student applying to a

universityl Sequence of steps to carry out taskl Error handling

4 e.g. what to do if recommendation letters not received on timel Workflows discussed in Section 26.2

Page 32: n Application Programs and User Interfaces · n The Web is a distributed information system based on hypertext. n Most Web documents are hypertext documents formatted via the HyperText

Object-Relational Mapping

n Allows application code to be written on top of object-oriented data model, while storing data in a traditional relational databasel alternative: implement object-oriented or object-relational

database to store object model4 has not been commercially successful

n Schema designer has to provide a mapping between object data and relational schemal e.g. Java class Student mapped to relation student, with

corresponding mapping of attributesl An object can map to multiple tuples in multiple relations

n Application opens a session, which connects to the databasen Objects can be created and saved to the database using

session.save(object)l mapping used to create appropriate tuples in the database

n Query can be run to retrieve objects satisfying specified predicates

Page 33: n Application Programs and User Interfaces · n The Web is a distributed information system based on hypertext. n Most Web documents are hypertext documents formatted via the HyperText

Object-Relational Mapping and Hibernate (Cont.)

n The Hibernate object-relational mapping system is widely usedl public domain system, runs on a variety of database systemsl supports a query language that can express complex queries

involving joins4 translates queries into SQL queries

l allows relationships to be mapped to sets associated with objects4 e.g. courses taken by a student can be a set in Student object

l See book for Hibernate code examplen The Entity Data Model developed by Microsoft

l provides an entity-relationship model directly to applicationl maps data between entity data model and underlying storage,

which can be relationall Entity SQL language operates directly on Entity Data Model

Page 34: n Application Programs and User Interfaces · n The Web is a distributed information system based on hypertext. n Most Web documents are hypertext documents formatted via the HyperText

Web Services

n Allow data on Web to be accessed using remote procedure call mechanism

n Two approaches are widely usedl Representation State Transfer (REST): allows use of standard

HTTP request to a URL to execute a request and return data4 returned data is encoded either in XML, or in JavaScript

Object Notation (JSON) l Big Web Services:

4 uses XML representation for sending request data, as well as for returning results

4 standard protocol layer built on top of HTTP4 See Section 23.7.3

Page 35: n Application Programs and User Interfaces · n The Web is a distributed information system based on hypertext. n Most Web documents are hypertext documents formatted via the HyperText

Disconnected Operations

n Tools for applications to use the Web when connected, but operate locally when disconnected from the Webl E.g. Google Gears browser plugin

4 Provide a local database, a local Web server and support for execution of JavaScript at the client

4 JavaScript code using Gears can function identically on any OS/browser platform

l Adobe AIR software provides similar functionality outside of Web browser

Page 36: n Application Programs and User Interfaces · n The Web is a distributed information system based on hypertext. n Most Web documents are hypertext documents formatted via the HyperText

Rapid Application Development

n A lot of effort is required to develop Web application interfacesl more so, to support rich interaction functionality associated with Web

2.0 applicationsn Several approaches to speed up application development

l Function library to generate user-interface elementsl Drag-and-drop features in an IDE to create user-interface elementsl Automatically generate code for user interface from a declarative

specificationn Above features have been in used as part of rapid application

development (RAD) tools even before advent of Webn Web application development frameworks

l Java Server Faces (JSF) includes JSP tag libraryl Ruby on Rails

4 Allows easy creation of simple CRUD (create, read, update and delete) interfaces by code generation from database schema or object model

Page 37: n Application Programs and User Interfaces · n The Web is a distributed information system based on hypertext. n Most Web documents are hypertext documents formatted via the HyperText

ASP.NET and Visual Studio

n ASP.NET provides a variety of controls that are interpreted at server, and generate HTML code

n Visual Studio provides drag-and-drop development using these controlsl E.g. menus and list boxes can be associated with DataSet objectl Validator controls (constraints) can be added to form input fields

4 JavaScript to enforce constraints at client, and separately enforced at server

l User actions such as selecting a value from a menu can be associated with actions at server

l DataGrid provides convenient way of displaying SQL query results in tabular format

Page 38: n Application Programs and User Interfaces · n The Web is a distributed information system based on hypertext. n Most Web documents are hypertext documents formatted via the HyperText

n Performance is an issue for popular Web sites l May be accessed by millions of users every day, thousands of

requests per second at peak timen Caching techniques used to reduce cost of serving pages by

exploiting commonalities between requestsl At the server site:

4 Caching of JDBC connections between servlet requests– a.k.a. connection pooling

4 Caching results of database queries– Cached results must be updated if underlying database

changes4 Caching of generated HTML

l At the client’s network4 Caching of pages by Web proxy

Page 39: n Application Programs and User Interfaces · n The Web is a distributed information system based on hypertext. n Most Web documents are hypertext documents formatted via the HyperText

n Parallel database systems consist of multiple processors and multiple disks connected by a fast interconnection network.

n A coarse-grain parallel machine consists of a small number of powerful processors

n A massively parallel or fine grain parallel machine utilizes thousands of smaller processors.

n Two main performance measures:l throughput --- the number of tasks that can be completed in a

given time intervall response time --- the amount of time it takes to complete a single

task from the time it is submitted

Page 40: n Application Programs and User Interfaces · n The Web is a distributed information system based on hypertext. n Most Web documents are hypertext documents formatted via the HyperText

n Homogeneous distributed databasesl Same software/schema on all sites, data may be partitioned

among sitesl Goal: provide a view of a single database, hiding details of

distributionn Heterogeneous distributed databases

l Different software/schema on different sitesl Goal: integrate existing databases to provide useful functionality

n Differentiate between local and global transactionsl A local transaction accesses data in the single site at which the

transaction was initiated.l A global transaction either accesses data in a site different from

the one at which the transaction was initiated or accesses data in several different sites.