Application Programs and User Interfaces Most database users do not use a query language like SQL An application program acts as the intermediary between users and the database Applications split into front-end middle layer backend Front-end:user interface ·Forms Graphical user interfaces Many interfaces are Web-based Database System Concepts-7th Edition 9.3 ©Silberscha乜,Korth and Sudarshan
Database System Concepts - 7 9.3 ©Silberschatz, Korth and Sudarshan th Edition Application Programs and User Interfaces ▪ Most database users do not use a query language like SQL ▪ An application program acts as the intermediary between users and the database • Applications split into ▪ front-end ▪ middle layer ▪ backend ▪ Front-end: user interface • Forms • Graphical user interfaces • Many interfaces are Web-based
Application Architecture Evolution Three distinct era's of application architecture Mainframe(1960's and 70's) Personal computer era(1980's) Web era(mid 1990's onwards) Web and Smartphone era(2010 onwards) Terminals Desktop PCs Web browsers Application Application Program Program Propietary Network or dial up phone lines Local Area Network Internet Mainframe Computer Web Application Server Database Database (a)Mainframe Era (b)Personal Computer Era (c)Web era Database System Concepts-7th Edition 9.4 @Silberschatz,Korth and Sudarshan
Database System Concepts - 7 9.4 ©Silberschatz, Korth and Sudarshan th Edition Application Architecture Evolution ▪ Three distinct era’s of application architecture • Mainframe (1960’s and 70’s) • Personal computer era (1980’s) • Web era (mid 1990’s onwards) • Web and Smartphone era (2010 onwards)
Web Interface Web browsers have become the de-facto standard user interface to databases Enable large numbers of users to access databases from anywhere ■ Avoid the need for downloading/installing specialized code,while providing a good graphical user interface Javascript,Flash and other scripting languages run in browser, but are downloaded transparently Examples:banks,airline and rental car reservations,university course registration and grading,an so on. Database System Concepts-7th Edition 9.5 @Silberschatz,Korth and Sudarshan
Database System Concepts - 7 9.5 ©Silberschatz, Korth and Sudarshan th Edition Web Interface ▪ Enable large numbers of users to access databases from anywhere ▪ Avoid the need for downloading/installing specialized code, while providing a good graphical user interface • Javascript, Flash and other scripting languages run in browser, but are downloaded transparently ▪ Examples: banks, airline and rental car reservations, university course registration and grading, an so on. Web browsers have become the de-facto standard user interface to databases
Sample HTML Source Text IDNameDepartment 00128ZhangComp.Sci. Search for: Student Instructor Name: Database System Concepts-7th Edition 9.9 @Silberschatz,Korth and Sudarshan
Database System Concepts - 7 9.9 ©Silberschatz, Korth and Sudarshan th Edition Sample HTML Source Text ID Name Department 00128 Zhang Comp. Sci. …. Search for: Student Instructor Name:
Display of Sample HTML Source ID Name Department 00128 Zhang Comp.Sci. 12345 Shankar Comp.Sci. 19991 Brandt History Search for: Student Name: submit Database System Concepts-7th Edition 9.10 @Silberschatz,Korth and Sudarshan
Database System Concepts - 7 9.10 ©Silberschatz, Korth and Sudarshan th Edition Display of Sample HTML Source Search for: Name: Student submit
Three-Layer Web Architecture web server network application server database server HTTP browser data server Database System Concepts-7th Edition 9.12 @Silberschatz,Korth and Sudarshan
Database System Concepts - 7 9.12 ©Silberschatz, Korth and Sudarshan th Edition Three-Layer Web Architecture
HTTP and Sessions The HTTP protocol is connectionless That is,once the server replies to a request,the server closes the connection with the client,and forgets all about the request In contrast,Unix logins,and JDBC/ODBC connections stay connected until the client disconnects retaining user authentication and other information Motivation:reduces load on server operating systems have tight limits on number of open connections on a machine Information services need session information E.g.,user authentication should be done only once per session Solution:use a cookie Database System Concepts-7th Edition 9.14 ©Silberscha乜,Korth and Sudarshan
Database System Concepts - 7 9.14 ©Silberschatz, Korth and Sudarshan th Edition HTTP and Sessions ▪ The HTTP protocol is connectionless • That is, once the server replies to a request, the server closes the connection with the client, and forgets all about the request • In contrast, Unix logins, and JDBC/ODBC connections stay connected until the client disconnects ▪ retaining user authentication and other information • Motivation: reduces load on server ▪ operating systems have tight limits on number of open connections on a machine ▪ Information services need session information • E.g., user authentication should be done only once per session ▪ Solution: use a cookie
Sessions and Cookies A cookie is a small piece of text containing identifying information Sent by server to browser Sent on first interaction,to identify session Sent by browser to the server that created the cookie on further interactions part of the HTTP protocol Server saves information about cookies it issued,and can use it when serving a request .E.g.,authentication information,and user preferences Cookies can be stored permanently or for a limited time Database System Concepts-7th Edition 9.15 ©Silberscha乜,Korth and Sudarshan
Database System Concepts - 7 9.15 ©Silberschatz, Korth and Sudarshan th Edition Sessions and Cookies ▪ A cookie is a small piece of text containing identifying information • Sent by server to browser ▪ Sent on first interaction, to identify session • Sent by browser to the server that created the cookie on further interactions ▪ part of the HTTP protocol • Server saves information about cookies it issued, and can use it when serving a request ▪ E.g., authentication information, and user preferences ▪ Cookies can be stored permanently or for a limited time
Servlets Java Servlet specification defines an APl for communication between the Web/application server and application program running in the server E.g.,methods to get parameter values from Web forms,and to send HTML text back to client Application program(also called a servlet)is loaded into the server Each request spawns a new thread in the server thread is closed once the request is serviced Programmer creates a class that inherits from HttpServlet And overrides methods doGet,doPost,... Mapping from servlet name (accessible via HTTP),to the servlet class is done in a file web.xml Done automatically by most IDEs when you create a Servlet using the IDE Database System Concepts-7th Edition 9.16 ©Silberscha乜,Korth and Sudarshan
Database System Concepts - 7 9.16 ©Silberschatz, Korth and Sudarshan th Edition Servlets ▪ Java Servlet specification defines an API for communication between the Web/application server and application program running in the server • E.g., methods to get parameter values from Web forms, and to send HTML text back to client ▪ Application program (also called a servlet) is loaded into the server • Each request spawns a new thread in the server ▪ thread is closed once the request is serviced • Programmer creates a class that inherits from HttpServlet ▪ And overrides methods doGet, doPost, … • Mapping from servlet name (accessible via HTTP), to the servlet class is done in a file web.xml ▪ Done automatically by most IDEs when you create a Servlet using the IDE
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.printIn("Query Result"); out.printin(""); ....BODY OF SERVLET (next slide)... out.printIn(""); out.close(); } } Database System Concepts-7th Edition 9.17 @Silberschatz,Korth and Sudarshan
Database System Concepts - 7 9.17 ©Silberschatz, Korth and Sudarshan th Edition 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(" Query Result"); out.println(""); ….. BODY OF SERVLET (next slide) … out.println(""); out.close(); } }