Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Web and DB - INT Evry Web and databases Bruno DEFUDE Computer Science Dept.

Similar presentations


Presentation on theme: "1 Web and DB - INT Evry Web and databases Bruno DEFUDE Computer Science Dept."— Presentation transcript:

1 1 Web and DB - INT Evry Web and databases Bruno DEFUDE Computer Science Dept

2 2 Web and DB - INT Evry WWW – Web advantages l Universal client l Easy to use l Open standards l Good integration with other Internet services and protocols l Extensible l Low software and network costs l Corporate network (Intranet), inter-companies network (extranet), WAN

3 3 Web and DB - INT Evry Why coupling web and DB? l Web is a kind of DB but »Without schema »Without query language »Without transactions, recovery, … »Without powerfull authorisation mechanism l DBs store huge amount of data which are interesting to publish on the web

4 4 Web and DB - INT Evry Simple coupling l Transform DBs into sets of static web pages »Simple »Redundency, problem of consistency »Disadvantages of web l Need to generate dynamic web pages constructed with DB content

5 5 Web and DB - INT Evry First solution: CGI scripts Browser (client) HTTP server DBMS url Html result CGI query string SQL HTML

6 6 Web and DB - INT Evry Pros and Cons of CGI l Simple and portable l Lots of code to write (one CGI per query!): can be improved with generic solutions l Not very efficient

7 7 Web and DB - INT Evry WWW – CGI problem Client 1Client 2Client 3 C G I Server Process Process 1 HTTP Server CGI Scripts

8 8 Web and DB - INT Evry WWW – the API Solution Client 1Client 2Client 3 Server Process HTTP Server API Set of functions Thread 1 Thread 2 Thread 3 CGI scripts are functions of a DLL, Processed As threads within the multi-threaded HTTP server

9 9 Web and DB - INT Evry FastCGI l Persistent CGI script CGI (daemon like) l A fastcgi script is splitted into 3 parts: »init : process one time »body : process at each request »ending : process one time l Init part must include costly part of the CGI code (connection to a DBMS, …) l Well adapted to DBMS access, but is persistent (can not handle numerous different connections)

10 10 Web and DB - INT Evry WWW – Web limitations l performances »Internet network => increase bandwith »CGI scripts => FastCGI, server-side scripts l security »HTTP => S-HTTP secure »TCP/IP level => SSL protocol

11 11 Web and DB - INT Evry WWW – Web Limitations (2) l Transaction management »not possible with HTTP 1.0 –no session mode –One can use "cookies" »Possible with HTTP 1.1 –Allows persistent connexion (TCP level) l User interface »HTML is not very powerfull to construct sophisticated UI »Java is more powerfull

12 12 Web and DB - INT Evry WWW – Web evolutions l At the beginning »access to informations –Distributed on the network –Represented by hypermedia documents l today »Software construction and processing –client/server, heterogeneous –Inside the same organization (Intranet)

13 13 Web and DB - INT Evry Coupling Web and DBMS l Gateways Principles l Java approach (applets, servlets, JSP) l Server-side scripting (PHP)

14 14 Web and DB - INT Evry Gateways Principles l Single-request gateways l Multiple-request gateways (transactional)

15 15 Web and DB - INT Evry Functionalities l (1) translate HTTP request (mapping environment variables to SQL statements) l (2) process SQL queries on the DBMS l (3) encode SQL results as HTML pages

16 16 Web and DB - INT Evry Process SQL queries l Program written using a DBMS API »DBMS-dependent approach (embedded SQL) »DBMS-independent approach (ODBC, JDBC or DBI for Perl) l Programming languages used »classical : C, C++, Ada, … if embedded SQL »Scripting language : Perl (with DBI)

17 17 Web and DB - INT Evry HTML encoding l Generic solution (can be automated): »select : HTML table »other query : string l Specific solution: a specific program for each query –Within the gateway (one gateway / query !) –Within the DBMS (one stored procedure / query) l Intermediate solution: »encoding can be parametrized (update form, hypertext navigation within the DB,…)

18 18 Web and DB - INT Evry DB access (simple html) Browser (client) HTTP server DBMS url Html result CGI Gateway query string SQLdata HTML

19 19 Web and DB - INT Evry Simple HTML example <input type="hidden" name="sqlstatement" value="select * from students where sname="> Give a name :

20 20 Web and DB - INT Evry DB access (client-side script) Browser (client) HTTP server DBMS url Html result gateway query string SQLdata HTML

21 21 Web and DB - INT Evry HTML with Javascript example <input type="hidden" name="sqlstatement" value="select * from students where sname="> Give a name : <input type="button" value="go" onClick="f1.sqlstatement.value+=f1.sname.value; f1.submit();">

22 22 Web and DB - INT Evry DB access (without http) Browser (client) + java, TCL program (applet, tclet …) DBMS Specific protocol Specific protocol: JDBC, IIOP (CORBA)

23 23 Web and DB - INT Evry Functionalities (1)(2)(3) Simple HTML Client-side script without http Specific CGI DBMS gateway or DBMS gateway or DBMS client

24 24 Web and DB - INT Evry Variations l DBMS-dependent or independent (native or ODBC) l Supported query language (SQL or subset, static vs dynamic) l HTML encoding (generic or specific) l efficiency

25 25 Web and DB - INT Evry Efficiency l CGI vs NSAPI, ISAPI (but proprietary solutions) l Decrease process number (if large number of clients) : multithreaded gateway

26 26 Web and DB - INT Evry Transactions l transaction = DB program (read and write sequence) l ACID properties –A : Atomicity –C : Consistency –I : Isolation –D : Durability

27 27 Web and DB - INT Evry Examples of transactional services l on-line ordering (music, books, planes, …) l bank l insurance l e-business!!!!

28 28 Web and DB - INT Evry Transactions and Web l Transaction = sequence of URL invocations (management context by the web?) l Transaction = ACID properties (ensured by the DBMS) l HTTP = no session support –Client-side management context (cookies) –Simulation of HTTP sessions (transactional web) –Use server-side scripting languages (PHP, ASP, JSP,...)

29 29 Web and DB - INT Evry Transactions and cookies Browser (client)http server cgi DBMS 1 1 1’ c1 2 c1 2’ c1, c2 3 fin c1, c2 4 sql(c1, c2) 5’ del(c1, c2) 4’ ok 1 : first access 1’ : c1 cookie is generated 2 : other access with c1 cookie transport 2’ : c1, c2 cookies are generated 3 : end of transaction with c1, c2 transport 4 : transaction is constructed and processed on the DBMS 5’ : cookies deletion

30 30 Web and DB - INT Evry Transaction and cookies (2) l Context is managed on client-side (cookies) l advantages: –Easy to code –DB access is done one time at the end of the session (DB resources are not blocked) –If no explicit user termination, nothing to do (at DB level)

31 31 Web and DB - INT Evry Transaction and cookies (3) l Cons –Not really transactional –Limited functionality –Lots of cgi scripts to code l Cookies problems –global to a user (no distinction between two windows) –global to a url (does not allow two different transactions on the same site at the same site)

32 32 Web and DB - INT Evry transactional gateway browser (Client) http ServercgidaemongatewayDBMS

33 33 Web and DB - INT Evry transactional gateway principles l Context is managed by a daemon on server-side l Need of a transaction id stored on client- side (cookie or rewritten URL) and on server-side (in an array of the daemon) l A gateway does not process a single query but a complete transaction (a sequence of queries)

34 34 Web and DB - INT Evry transactional gateway operations (1) l 1 : transaction beginning request (implicite or explicite) –An id is allocated by the daemon, transactions array is updated, a gateway is launched, an id is send back to the client (cookie or rewritten URL) l 2 : DB operation request –The request is routed by the daemon on the right gateway using the transaction id and the transactions array

35 35 Web and DB - INT Evry transactional gateway operations(2) l 3 : transaction ending request –implicit : error, timeout –explicit : idem 2 + update of transactions array, id is deleted on client-side and the gateway is stopped

36 36 Web and DB - INT Evry transactional gateway Resume l Pros –really transactional –generic solution l Cons –complex architecture –DB resources are blocked until the end of the transaction –Need to detect a user « abort » (timeout)

37 37 Web and DB - INT Evry Scripting language (server- side) l Offer a programming language integrated to the web (ability to have calls from a web page, associated to a HTTP server) l run-time of the language offers session support (and consequently of transactions) l PHP, servlet - JSP, ASP, XSP (Cocoon) l see Java and PHP for more details

38 38 Web and DB - INT Evry Java and Web l JVM concept is well adapted for Web l Java language is widely used l JDBC (standard API for DBMSs) l Applets l servlets l Java Server Pages

39 39 Web and DB - INT Evry Java - Java and Web l language for W3 client »applet = small compiled Java application –Loaded from a W3 server –Running is secured by the client JVM l language for W3 server »servlet = compiled Java application –Stored on server-side –Run by server-side JVM

40 40 Web and DB - INT Evry Servlets l Servlet 2.2 (http://java.sun.com/servlet) l Tomcat from Apache is the reference implementation l Same as CGI for Java l CGI extensions (session, buffer management, redirection/chaining)

41 41 Web and DB - INT Evry Servlet Architecture Web browser Client Servlet container servlet2 servlet1 HTTP Server Container manages servlets (activation, desactivation)

42 42 Web and DB - INT Evry Servlet object Model request Object servlet1 Response Object session Object getParameter getAttribute getHeaders getCookies setBufferSize setHeader setRedirect getAttribute

43 43 Web and DB - INT Evry JSP l JSP 1.2 (http://java.sun.com/jsp) l Tomcat from Apache is the reference implementation l Scripts included into HTML pages l Same as ASP, PHP but for Java l compiled into servlets l portability of Java l Server-side scripting with extensibility using tag libraries

44 44 Web and DB - INT Evry Example of JSP page Welcome Date: Day : Year : Good Morning Good Afternoon

45 45 Web and DB - INT Evry JSP page Components (1) l JSP actions (or tags) : allow to call beans (XML syntax) l directives : processed by JSP engine during page compilation into servlets (include, import,...) l declarations : as in Java

46 46 Web and DB - INT Evry JSP page Components (2) l expressions : variables or constants integrated into the HTML result page l scriplets : blocks of Java code integrated into a JSP page l comments

47 47 Web and DB - INT Evry Personalized Tags l One can add his/her own tags to simplify JSP page writing l tags libraries l mechanism to define new tags is complex

48 48 Web and DB - INT Evry Example use of tag libraries select number, sname from students The first 10 students are: Number Name

49 49 Web and DB - INT Evry Example (cont) l Definition of a queryBlock tag composed itself by other tags (queryStatement, queryCreateRows) l Allow to mask JDBC code to the page developer l a tag is defined by a descriptor (XML document) + a Java class for implementation

50 50 Web and DB - INT Evry XML and Web l XML offers a clear splitting between logical structure and presentation l Allow to develop software producing different format outputs of the same XML source (HTML vs PDF, WML vs HTML,...)

51 51 Web and DB - INT Evry Publishing Environment for XML l Software environment allowing to produce different output formats from the same XML source l Cocoon from XML-Apache l Often based on Java implementation (Servlet, JSP)

52 52 Web and DB - INT Evry Cocoon Web browser or PDA Client Doc. XML XSLT Interpreter FOP InterpreterPDF Doc. HTML Doc. WML Doc. Cocoon 1 2 4 4 5 6 Apache + Tomcat 3

53 53 Web and DB - INT Evry Conclusion l Numerous software products and several solutions l choice depends on the objective: »Query web site: simple gateways of server-side scripting language PHP, ASP »Different web sites produced from the same source: XML »Corporate portals: JSP or Cocoon


Download ppt "1 Web and DB - INT Evry Web and databases Bruno DEFUDE Computer Science Dept."

Similar presentations


Ads by Google