Giáo trình Công nghệ Web và ứng dụng - Kiến trúc Web

Vì sao dùng N-Layer Architecture?  Tách các dịch vụ trong quá trình xử lý nhằm tái sử dụng chúng  Kết nối lỏng lẻo nhằm giảm ảnh hưởng lên cả hệ thống  Dễ bảo trì (in terms of code)  Có thể mở rộng (modular)  Trade-offs  Giảm sự phức tạp  Tăng khả năng chịu lỗi

pdf26 trang | Chia sẻ: hoant3298 | Lượt xem: 602 | Lượt tải: 0download
Bạn đang xem trước 20 trang tài liệu Giáo trình Công nghệ Web và ứng dụng - Kiến trúc Web, để xem tài liệu hoàn chỉnh bạn click vào nút DOWNLOAD ở trên
Kiến trúc Web Nội dung  Kiến trúc web  Giao thức HTTP  Mô hình MVC Kiến trúc Web  Kiến trúc Web Platform  Platform • Hardware • Software modules & configurations • Choice of software platform (e.g., J2EE, .NET)  Kiến trúc Web Application  Mô hình hóa các tiến trình xử lý  Trong một lĩnh vực cụ thể  Module hóa và phức tạp Kiến trúc Web Platform  Web platform dựa trên các thành phần sau  TCP/IP  HTTP  HTML  Mô hình kiến trúc Client/Server  Là mô hình phức tạp  Các thành của network (firewall, proxy, load balancer)  Các thành phần của intranet (web server, application server, database, web services) Mô hình Web (tầng ứng dụng)  Các thành phần ngữ nghĩa của Web  URLs/URIs  HTTP  HTML  Dịch vụ Web: Nội dung động và có tính tương tác  PHP, Python, Java Clients (browsers) HTTP Server HTTP for transport URL/URI for addressing HTML/XHTML for display PHP, python etc. for interaction Mô hình Web (các tầng giao thức) HTTP TCP IP Ethernet interface Ethernet Client Router IP Ethernet interface SONET interface IP SONET interface Ethernet interface SONET link HTTP TCP IP Ethernet interface Web server Ethernet Router IP packet IP packet IP packet TCP segment HTTP message Giao thức HTTP  Những bước xử lý của browser Client Origin server HTML DNS server DNS query Establish TCP connection HTTP request Optional parallel connections HTTP response HTTP transaction Giao dịch của HTTP  Một giao dịch của giao thức HTTP là một request và một response (một phản hồi của một request nào đó) giữa web client và web server GET / HTTP/1.1 Accept: image/gif, image/x-xbitmap, image/ jpeg, image/pjpeg, */* Accept-Language: en-us Accept-Encoding: gzip, deflate User-Agent: Mozilla/4.0 (compatible; MSIE 5.01; Windows NT) Host: www.eurecom.fr Connection: Keep-Alive Client Origin server HTTP/1.1 200 OK Date: Mon, 15 Jul 2002 08:49:00 GMT Server: Apache/1.3.26 (Unix) PHP/4.2.1 Last-Modified: Wed, 12 Jun 2002 08:49:49 GMT ETag: "2a-50ea-3d070b2d" Accept-Ranges: bytes Content-Length: 20714 Keep-Alive: timeout=15, max=100 Connection: Keep-Alive Content-Type: text/html ... HTML HTTP Message  HTTP message ở dạng ASCII text, gồm:  Một dòng yêu cầu Method Request-URI HTTP-Version (Request-Line) HTTP-Version Status-Code Reason-Phrase (Status-Line)  Các trường Header field-name ":" [ field-value ]  Một dòng trống  Phần thân thông báo (tùy chọn) HTTP Request  Ví dụ GET /foo.html HTTP/1.1 Accept: image/gif, image/x-xbitmap, image/ jpeg, image/pjpeg, */* Accept-Language: en-us Accept-Encoding: gzip, deflate User-Agent: Mozilla/4.0 (compatible; MSIE 5.01; Windows NT) Host: www.eurecom.fr Connection: Keep-Alive GET /foo.html HTTP/1.1 — request "/foo.html" using HTTP version 1.1 Accept: — types of documents accepted by browser Accept-Language: — preferred language is english Accept-Encoding: — browser understands compressed documents User-Agent: — identification of browser (real type is IE 5.01) Host: — what the client thinks the server host is Connection: — keep TCP connection open until explicitly disconnected HTTP Response  Ví dụ: HTTP/1.1 200 OK Date: Mon, 15 Jul 2002 08:49:00 GMT Server: Apache/1.3.26 (Unix) PHP/4.2.1 Last-Modified: Wed, 12 Jun 2002 08:49:49 GMT ETag: "2a-50ea-3d070b2d" Accept-Ranges: bytes Content-Length: 20714 Connection: close Content-Type: text/html ... HTTP/1.1 200 OK — document found (code 200); server is using HTTP 1.1 Date: — current date at the server Server: — software run by the server Last-Modified: — most recent modification of the document ETag: — entity tag (unique identifier for the server resource, usable for caching) Accept-Ranges: — server can return subsections of a document Content-Length: — length of the body (which follows the header) in bytes Connection: — the connection will close after the server's response Content-Type: — what kind of document is included in the response ... — document text (follows blank line) Client Methods  GET Retrieve a resource from the server (static file, or dynamically-generated data)  HEAD Get information about a resource (but not the actual resource)  POST Client provides some information to the server, e.g., through forms (may update the state of the server)  PUT Provide a new or replacement resource to put on the server  DELETE Remove a resource from the server  OPTIONS (HTTP 1.1) Request other options for an URI (methods understood by a server or allowed for a given URI)  TRACE (HTTP 1.1) Ask proxies to declare themselves in the headers (used for debugging)  CONNECT (HTTP 1.1) Used for HTTPS (secure HTTP) through a proxy HTTP Caching  Dữ liệu Cache gần người dùng hơn  Improves Web performance, reduces load on server  Cache control directives in HTTP header (no cache, age, etc.) GET Client 1 Cache server Origin server Client 2 GET 200 OK 200 OK GET 200 OK HTTP Client Authentication  Cơ chế bảo mật đơn giản thông qua username/password  Basic scheme: username:password base-64 encoded echo -n “user:password" | openssl base64 echo "c2NvdHQ6dGlnZXI=" | openssl base64 -d GET /private/ HTTP/1.1 Client Origin server HTML HTTP/1.1 200 OK ... HTTP/1.1 401 Unauthorized WWW-Authenticate: Basic realm="secret" GET /private/ HTTP/1.1 Authorized: Basic SHY3GH7D3SH== Username: joe Password: ******** Cookies  Cho phép Web servers lưu trạng thái của Client  Dùng cặp khóa – giá trị  Thường dùng quản lý các phiên giao dịch session  Cookie có thể truy xuất bởi một site/domain  Server có thể định thời gian hết hạn  Client có thể từ chối cookie, giới hạn kích thước, thời gian Client Origin server GET 200 OK Set-Cookie: ABC=XYZ GET Cookie: ABC=XYZ 200 OK Mô hình: Model View Controller  Mô hình được sử dụng trong Smalltalk (1979)  Tách riêng giữa tầng dữ liệu và hiển thị  Dễ dàng phát triển Mô hình: Model View Controller  Model  Tượng trưng cho dữ liệu trong phần mềm ứng dụng  View  Tầm nhìn hay khung nhìn (view) bao gồm các thành phần của giao diện người dùng  Controller  Quản lý sự trao đổi dữ liệu  Các nguyên tắc nghề nghiệp trong các thao tác liên quan đến mô hình Model-View-Controller 2 cho Web  Sự thích ứng của MVC đối với Web  Kết nối không bền vững giữa client và server  Thông báo những thay đổi  Truy vấn lại server để phát hiện những thay đổi Client/Server (2-Layer) Client Web/App Server Database Services Dynamic HTML Static HTML Client Server Client/Server (2-Layer) N-Layer Architectures Client Application Server (Business Logic, Connectors, Personalization, Data Access) Presentation Layer Firewall Proxy Web Server DBMS B2B Backend (Legacy Application, Enterprise Info System) Business Layer Data Layer N-Layer Architectures Vì sao dùng N-Layer Architecture?  Tách các dịch vụ trong quá trình xử lý nhằm tái sử dụng chúng  Kết nối lỏng lẻo nhằm giảm ảnh hưởng lên cả hệ thống  Dễ bảo trì (in terms of code)  Có thể mở rộng (modular)  Trade-offs  Giảm sự phức tạp  Tăng khả năng chịu lỗi JSP-Model-1 Architecture JSP-Model-2 Architecture 1. user request 2. create/change model 3. create/change view 4. generate output 5. server response Struts Architecture 1. user request 2. forwarding to controller 3. create/change model 4. create/change view 5. generate output 6. server response

Các file đính kèm theo tài liệu này:

  • pdfcong_nghe_web_va_ung_dung_nguyen_minh_vi2_kientruc_8514_2021634.pdf
Tài liệu liên quan