IS907 Java EE World Wide Web Overview World
IS-907 Java EE World Wide Web - Overview
World Wide Web - History • Tim Berners-Lee, CERN, 1990 • Enable researchers to share information: • Remote Access • Not restricted to particular type of computer(s) • Non-centralised • Access to existing data • Users can add data • Annotations • Data analysis
Web, Internet, internet. . . • internet – connection between local networks • Internet – the global tcp/ip based internet • (World Wide) Web/W 3 – an http-based application that uses the Internet for data transport
Web Architecture • The World Wide Web uses a client-server architecture • Clients (browsers) provides the user interface and displays data • Servers provide data to the clients on request • Clients and servers are programs • The client and server can run on the same computer, or on different computers • The computer where the server runs is often called host
Building blocks of the web • http – the Hyper. Text Transfer Protocol: The rules for communication between clients and servers. • URI/URN/URL – Uniform Resource Identifier/ Name/ Locator: The rules for naming data objects on the web. • html – Hyper. Text Markup Language: The syntax rules for documents.
Hyper. Text Markup Language • the document format of the web • standardized: • • • XHTML 1. 1 • XHTML 1. 0 http: //www. w 3. org/TR/2002/REC-xhtml 1 -20020801/ • HTML 4. 01 http: //www. w 3. org/TR/html 401/ XHTML is defined as an XML application • • http: //www. w 3. org/standards/techs/html#w 3 c_all syntax is stricter than plain HTML We will use XHTML 1. 0 Even Åby Larsen (even. larsen@uia. no) IS-102 Introduksjon 6
XHTML pages • starts with a document declaration: <? xml version="1. 0" encoding="UTF-8"? > <!DOCTYPE html PUBLIC "-//W 3 C//DTD XHTML 1. 0 Transitional//EN" "http: //www. w 3. org/TR/xhtml 1/DTD/xhtml 1 -transitional. dtd"> • The document contains elements (tags) • the top level element is html • all tags must have a matching end tag <h 1>Hello World!</h 1> • the end tag can be abbreviated for empty elements: <br/> Even Åby Larsen (even. larsen@uia. no) IS-102 Introduksjon 7
Simple XHTML page <? xml version="1. 0" encoding="UTF-8"? > <!DOCTYPE html PUBLIC "-//W 3 C//DTD XHTML 1. 0 Transitional//EN" "http: //www. w 3. org/TR/xhtml 1/DTD/xhtml 1 -transitional. dtd"> <html> <head> <meta http-equiv="Content-Type“ content="text/html; charset=UTF-8" /> <title>Hello</title> </head> <body> <h 1>Hello World!</h 1> <p><a href="about. html">About. . . </a></p> </body> </html> Even Åby Larsen (even. larsen@uia. no) IS-102 Introduksjon 8
Style sheets • • Used to define the layout and visual properties of html documents • fonts • colours • margins • . . . Cascading Style Sheets (css) • http: //www. w 3. org/TR/CSS 2/ Even Åby Larsen (even. larsen@uia. no) IS-102 Introduksjon 9
Uniform Resource Locators • General format: scheme: //host/path • Example: http: //java. sun. com/j 2 se/1. 5. 0/docs/api/ • • scheme = http • host = java. sun. com • path = j 2 se/1. 5. 0/docs/api Relative URL • path from current page to another one. • if the page http: //mynetshop. com/index. html contains a link to products/computers. html • it is interpreted by the browser as http: //mynetshop. com/products/computers. html
The Hyper. Text Transfer Protocol • Request / Response protocol Client • Message format: • one or more headers • blank line • message body Server Request Response
HTTP Request Message types • GET – used for normal links to get a page, image, . . . • HEAD – just like GET, but no page returned • POST – used to send data to the server • PUT – create a new object on the web (seldom used) • DELETE – remove an object from the web • TRACE • OPTIONS • CONNECT
HTTP GET Request Message Example GET / j 2 se/1. 5. 0/docs/api HTTP/1. 1 Host: java. sun. com
HTTP Response Message Example HTTP/1. 1 200 OK Date: Tue, 28 Aug 2006 07: 33: 45 GMT Content-Type: text/html <html> html document. .
The POST Request The data from a form are transferred in the request body: POST /register HTTP/1. 1 Host=my. host. com More=headers paramname=value. . .
Simple web server for static content while (true) { get next request; read contents of file %DOCROOT%/request. path; create a response message; set response headers; set response. body = file contents; send response; }
Dynamic web pages • • Dynamic presentation • uses Java. Script and style sheets • page remains the same • user may interact with presentation Dynamic content • server respons with different content depending on input
Dynamic content • The server doesn’t just map the URL to a filename • It must • • map the URL to a program, • run the program, • and send the output of the program in the body of the response the program can do anything: • get data from a file, or a database • do some computation • connect to another system • . . .
Running a program. . . ? • Actually running an external program (CGI) • the server sends the request to another program • Server ”plugins” (e. g. servlets) • the server handles the request by calling the plugin code • Scripts inside the html files (ASP, PHP. . . ) • the server reads a file (just as for static content), but scans the file for commands, and replaces the commands with the result of executing them
web server for dynamic content while (true) { get next request; create a response message; if (cgi-url) { extract program name from request; run the program; set response. body=program output; } else if (plugin-url) { call the plugin; set response. body=plugin output; } else { read contents of file %ROOT%/request. path; if (file contains script) execute script; set response. body = file contents; } send response; }
- Slides: 20