week7_com206
week7_com206
2
Database System Concepts - 7th Edition 8.2 ©Silberschatz, Korth and Sudarshan
Course Content (Subject to Change)
3
Database System Concepts - 7th Edition 8.3 ©Silberschatz, Korth and Sudarshan
Application Programs and User Interfaces
Database System Concepts - 7th Edition 8.5 ©Silberschatz, Korth and Sudarshan
Application Architecture Evolution
Three distinct era’s of application architecture
Mainframe (1960’s and 70’s)
Personal computer era (1980’s) The HTML standard is
Web era (mid 1990’s onwards) independent of the
operating system or
Web and Smartphone era (2010 onwards)
browser. No installation
Requests from a
browser are sent to a
user machines had direct access to web server, which in
databases, leading to security risks. turn executes an
application program
Database System Concepts - 7th Edition 8.6 to processKorth
©Silberschatz, theandrequest
Sudarshan
Web Interface
Database System Concepts - 7th Edition 8.7 ©Silberschatz, Korth and Sudarshan
Sample HTML Form
Database System Concepts - 7th Edition 8.11 ©Silberschatz, Korth and Sudarshan
Sample HTML Source Text
<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>
Database System Concepts - 7th Edition 8.12 ©Silberschatz, Korth and Sudarshan
Display of Sample HTML Source
Database System Concepts - 7th Edition 8.13 ©Silberschatz, Korth and Sudarshan
Three-Layer Web Architecture
Database System Concepts - 7th Edition 8.15 ©Silberschatz, Korth and Sudarshan
Three-Layer Web Architecture
Database System Concepts - 7th Edition 8.16 ©Silberschatz, Korth and Sudarshan
Two-Layer Web Architecture
Database System Concepts - 7th Edition 8.17 ©Silberschatz, Korth and Sudarshan
HTTP and Sessions
Database System Concepts - 7th Edition 8.19 ©Silberschatz, Korth and Sudarshan
Sessions and Cookies
Database System Concepts - 7th Edition 8.20 ©Silberschatz, Korth and Sudarshan
Servlets
Database System Concepts - 7th Edition 8.21 ©Silberschatz, Korth and Sudarshan
Example Servlet Code
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();
}
}
Database System Concepts - 7th Edition 8.22 ©Silberschatz, Korth and Sudarshan
Example Servlet Code
Database System Concepts - 7th Edition 8.23 ©Silberschatz, Korth and Sudarshan
Servlet Support
Database System Concepts - 7th Edition 8.24 ©Silberschatz, Korth and Sudarshan
Server-Side Scripting
Database System Concepts - 7th Edition 8.25 ©Silberschatz, Korth and Sudarshan
Java Server Pages (JSP)
A JSP page with embedded Java code
HTML programmers allowed to mix static HTML with dynamically
generated HTML.
<html>
<head> <title> Hello </title> </head> Java Code
<body>
<% if (request.getParameter(“name”) == null)
{ out.println(“Hello World”); }
else { out.println(“Hello, ” + request.getParameter(“name”)); }
%>
</body>
</html>
JSP is compiled into Java + Servlets. JSP scripts are actually translated
into servlet code that is when compiled
Database System Concepts - 7th Edition 8.26 ©Silberschatz, Korth and Sudarshan
PHP
PHP is a scripting language that is widely used for server-side
scripting.
Extensive libaries including for database access using ODBC
<html>
PHP Code
<head> <title> Hello </title> </head>
<body>
<?php if (!isset($_REQUEST[‘name’]))
{ echo “Hello World”; }
else { echo “Hello, ” + $_REQUEST[‘name’]; }
?>
</body>
</html>
Database System Concepts - 7th Edition 8.27 ©Silberschatz, Korth and Sudarshan
Javascript
Javascript very widely used
Forms basis of new generation of Web applications (called Web 2.0
applications) offering rich user interfaces
Javascript functions can
Check input for validity
Modify the displayed Web page, by altering the underling document
object model (DOM) tree representation of the displayed HTML text
Communicate with a Web server to fetch data and modify the current
page using fetched data, without needing to reload/refresh the page
Forms basis of AJAX technology used widely in Web 2.0
applications
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
The browser parses HTML code into an in-memory tree structure
defined by a standard called the Document Object Model (DOM).
JavaScript code can modify the tree structure to carry out certain
operations.
Database System Concepts - 7th Edition 8.28 ©Silberschatz, Korth and Sudarshan
Javascript
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>
Database System Concepts - 7th Edition 8.29 ©Silberschatz, Korth and Sudarshan
Application Architectures
Database System Concepts - 7th Edition 8.30 ©Silberschatz, Korth and Sudarshan
Application Architectures
To handle their complexity, large applications are often broken into several
application layers:
The presentation or user-interface layer, which deals with user interaction.
A single application may have several different versions of this layer,
corresponding to distinct kinds of interfaces such as web browsers and
user interfaces of mobile phones, which have much smaller screens.
In many implementations, the presentation/user-interface layer is itself
conceptually broken up into layers, based on the model-view-controller
(MVC) architecture.
Database System Concepts - 7th Edition 8.31 ©Silberschatz, Korth and Sudarshan
Application Architectures
business-logic layer
provides high level view of data and actions on data
– often using an object data model
hides details of data storage schema
data access layer
interfaces between business logic layer and the underlying
database
provides mapping from object model of business layer to relational
model of database
Database System Concepts - 7th Edition 8.32 ©Silberschatz, Korth and Sudarshan
Business Logic Layer
Provides abstractions of entities
E.g., students, instructors, courses, etc
Enforces business rules for carrying out actions
E.g., student can enroll in a class only if she has completed
prerequsites, and has paid her tuition fees
Supports workflows which define how a task involving multiple
participants is to be carried out
E.g., how to process application by a student applying to a university
Sequence of steps to carry out task
Error handling
E.g. what to do if recommendation letters not received on time
Database System Concepts - 7th Edition 8.33 ©Silberschatz, Korth and Sudarshan
Application Architecture
Figure shows these layers, along with a sequence of steps
taken to process a request from the web browser.
The labels on the arrows in the figure indicate the order of
the steps.
Database System Concepts - 7th Edition 8.34 ©Silberschatz, Korth and Sudarshan
Application Architecture
When the request is received by the application
server, the controller sends a request to the model.
Database System Concepts - 7th Edition 8.35 ©Silberschatz, Korth and Sudarshan
Application Architecture
The model processes the request, using business
logic, which may involve updating objects that are
part of the model, followed by creating a result
object.
Database System Concepts - 7th Edition 8.36 ©Silberschatz, Korth and Sudarshan
Application Architecture
The model in turn uses the data-access layer to
update or retrieve information from a database.
Database System Concepts - 7th Edition 8.37 ©Silberschatz, Korth and Sudarshan
Application Architecture
.The result object created by the model is sent to the
view module, which creates an HTML view of the
result to be displayed on the web browser.
Database System Concepts - 7th Edition 8.38 ©Silberschatz, Korth and Sudarshan
Application Architecture
The view may be tailored based on the characteristics
of the device used to view the result
Database System Concepts - 7th Edition 8.39 ©Silberschatz, Korth and Sudarshan
End of Week 7
Database System Concepts - 7th Edition 8.40 ©Silberschatz, Korth and Sudarshan