910 likes | 923 Views
Learn how the web works, essential technologies, client-side vs. server-side coding, HTTP protocols, HTML basics, and more to navigate the digital landscape effectively.
E N D
Contents • How the web works • Fundamental Web Technologies • Client Side Coding • Server Side Coding Web Technologies
Client-Server Architecture Request Server Client Response Web Technologies
Accessing a Web Page DNS Server google.com 192.168.1.4 tuc.gr 147.27.15.134 . . domainName server IP 2 google.com 192.168.1.4 3 1 192.168.1.4 Server Response 4 Browser Server Client Web Technologies
URL Analysis Protocol Domain Name http://www.tuc.gr/students.html File (web page) World Wide Web Web Technologies
DNS server • Domain Name System (DNS) manages public names of Web sites and transforms them to IPs (data base of Web site names and IPs) • A DNS server is registered to join the Domain Name System • DNS servers are organized in hierarchy • 13 Root servers (named A, B, C … M) • Lower level DNS Servers maintain only pieces of this information, public providers and others • Local DNS servers are maintained by the ISPs, primary and back-up DNS servers, gateways, manually or by DHCPs. • Queries are propagated upwards in hierarchy https://www.techradar.com/news/best-dns-server
Protocols Define rules to govern the request-response process Define the structure of the request-response messages so they can be machine understandable. Common protocols: 'http://‘ , 'https://' , 'ftp://' Web Technologies
HTTP Protocol HyperText Transfer Protocol Text based 2 Types of messages: Requests & Responses Status Line Headers Blank Line Body Web Technologies
Request Method Request URI HTTP-version Headers Body Web Technologies
Response HTTP-version Response Code Headers Body Web Technologies
Request - Response • GET /people/students.htmlHTTP/1.1 • Host: www.tuc.gr • User-agent: Mozilla/4.0 • Connection: close • Accept-language:gr Http Request Example: • HTTP/1.1 200 OK Content-Type: text/html • Content-Length: 6827 Connection: close • Server: Apache Tomcat/4.0.2 • Last-Modified: Tue, 12 Feb 2002 18:24:48 • ... • <body> Http Response Example: Response Codes: 401 (Not found) 200 (Ok) etc Web Technologies
PUT - POST • Typically PUT to create resources, POST to update resources but this isn’t exactly the way they are meant to work • PUT to create and update resources when their exact location is known – idempotent method • POST when their exact location is not known and is decided by the server – not idempotent or safe • Idempotent method: can be called many times and the outcome is always the same, safe method Web Technologies
PUT - POST Will be created at this location Created at this location, Decided by server Web Technologies
HTTP Protocol – Response Codes • 100–199 Informational (101 switch protocol) • 200–299 Successfulpageaccess • 300–399 Redirecttherequest • 400–499 Clienterrors • 500–599 Servererrors Web Technologies
HTML HyperTextMarkup Language The language to create web pages Not a programming language. Used to visualize Content. Has pre-defined presentation semantics that denote how the structured data is to be presented. Web Technologies
HTML Document Structure <HTML> <HEAD> </HEAD> <BODY> </BODY> </HTML> Beginning of HTML Document Head Content Only the Body is displayed!!! Body Content End of HTML Document https://www.w3schools.com
HEAD Elements Title: Adds a title to the web page. (Displayed in the browser tab, On bookmarks, on search engines, etc) <title> Web Page Title </title> <style> body {background:#000;} a{ color:red; font-weight:bold; }</style> Style: Adds css rules to a page <linkrel="stylesheet" type="text/css" href="style.css"> Link: Defines the relationship between a document and an external resource (css file – formatting instructions). Web Technologies
HTML Based on HTML element tags ( <h1> ,</h1>, <img> etc.) Browsers read HTML files to compose visible or audible web pages. HTML tags are not displayed. They are used to interpret the content of pages. HTML BROWSER <H1> This is a title </H1> First line. Second line. <br/> <b> Third Line </b> This is a title First line. Second line. Third Line Web Technologies
Divs In HTML we have BLOCK and INLINE elements BLOCK elements: Start and end with a new line. Examples: <h1> - <h6>, <p>, <ul>/<li>, <uo>/<li>, <table> INLINE elements: Start and end with a new line Examples: <b>, <em>, <td>, <a>, <img> Divs are BLOCK elements! Web Technologies
HTML <a> • A link to W3CSchools • <ahref="http://www.w3schools.com">Visit W3Schools.com!</a> • Will produce • Visit W3Schools.com! • If clicked will open : http://www.w3schools.com Web Technologies
HTML HTML Attributes: Name-Value Pairs E.g., width = “100” , Border = “2” etc. The image is a link – you can click on it . <a href=‘http://example.org’ > <img src=“dog.png" width="50" height="50" border=“0“ > </a> In BROWSER you see: Web Technologies
CSS Cascading Style Sheets A set of rules used to describe the look and formatting of an HTML document Designed to enable the separation of content from presentation <div> groups elements to format them with CSS Internal (inline) or External (Separate file) CSS Inline CSS Browser Styles in HTML. <h1 style="color:red"> Styles in HTML. </h1> Web Technologies
CSS Example 1 Web Technologies
CSS Example 2 Web Technologies
HTML DOM • When a page is loaded the browser creates a Document Object Model of the page Web Technologies
Javascript Client Side Scripts Interact with user (e.g., dialogue box, confirm box, button) Control browser behavior (e.g., Don’t allow right click) Alter the document content dynamically (e.g., use events) Communicate asynchronously (Ajax) with the server Can be placed in the <body> and the <head> sections Web Technologies
Javascript Example Any number of <script>s within <body> or <head> Define Functions Inside “scripts” Web Technologies
getElementById( ) • The main Javascript method • document.getElementById("demo").innerHTML = "Hello” will search for element with id=“demo” and change its content to “Hello” • document.getElementById("demo").style.fontSize = "25px”will change font size of element with id=“demo” • document.getElementById("demo").style.display="block” will hide element with id=“demo” Web Technologies
Output • JavaScript can "display" data in different ways: • Writing into an alert box, using window.alert( ) • Writing into the HTML output using document.write( ) • Writing into an HTML element, using innerHTML • Writing into the browser console, using console.log( ) Web Technologies
Document.write() Will replace all existing HTML with the value in ( ..) If button is pressed, 11 will replace html content on screen Web Technologies
innerHTML Will replace content of id=“demo” with 11 11 will appear in existing HTML Web Technologies
innerHTML Javascript code: Before button is clicked: After button is clicked: Web Technologies
Javascript Functions Javascript with function declared Before button is clicked After button is clicked Web Technologies
Javascript Forms If you click Form data will be sent to page: /action_page.php then Web Technologies
JavascriptDatatypes Example Output: Saab Web Technologies
Javascript Object Output: Web Technologies
Javascript Object Notation (JSON) • A format for sending & receiving objects/xml • Objects with many attribute value pairs • varjson='{"firstName":"John”, ”lastName”:”Doe”}’; JSON • This is equivalent to varjobj= {firstName: “John”, lastName: “Doe”}; JS Object Web Technologies
JS (JSON) Object vs JSON • JSON: JavaScript Object Notation • Closely related to JS Object, very similar syntax, all JS Object data are valid JSON data and the reverse • JSON is language independent format used to exchange information between services but JS Object is for JS use only JS Object JSON https://medium.com/@easyexpresssoft/object-literal-vs-json-7a2084872907
JS Object, JSON Conversion • Javascript has built-in support for conversion between JSON and javascript object • JSON.stringify(obj): converts an JS object ‘obj’ to a JSON data, • JSON.parse(data): coverts JSON (text) data ‘data’ to JS object Web Technologies
JSON - JS Object example Output: Web Technologies
JSON Example JSON Converts JSON to JS Object Web Technologies
JSON Array Web Technologies
JSON vs XML • Syntax for storing / exchanging data, alternative to XML JSON XML Web Technologies
AngularJS • AngularJS extends HTML attributes with Directives, and binds data to HTML with Expressions • Directive: introduces new syntax that associates new behavior to DOM elements (attribute, names) via event listeners • Built-in, custom directives • Can be added to HTML with the <script> tag: Web Technologies
Built-in Directives • ng-app: initializes AngularJS application, defines <div> element as the owner of the AngularJs expression • ng-model: binds value of an input field to variable created in AngularJS • ng-bind: binds to value of innerHTML (print/use value) • ng-init: initializes application data • ng-repeat: repeats HTML elements • use double braces {{}} or ng-bind to display content from the model : <p>First name: {{firstname}}</p> Web Technologies
AngularJS Example <div> is owner of Angular JS application replace the content of HTML element with this value Same as <p>{{name}}</p> Web Technologies
AngularJS Example init value OUTPUT <p>Your wrote: <span ng-bind="name"><span></p> Web Technologies
ng-repeat, ng-init Code: Output: Web Technologies
PHP • Server scripting language for making dynamic and interactive Web pages (alternative to ASP) • PHP scripts execute on the server, various platforms • PHP code combined with HTML, CSS, JQUERY, Javascript.. • What can PHP do • can generate dynamic page content • Manipulate files (open, read, write, delete, close files) on server • can collect form data • can send and receive cookies • can add, delete, modify data in database • can be used to control user-access • can encrypt data Web Technologies