Lec2-2 - Web - Development - Models
Lec2-2 - Web - Development - Models
Term 2020-2
Content
1
Client-Server Model
Server Roles
2
Client Roles
Client-Server Advantages
3
3-Tier Architecture
4
Programming Languages
JavaScript
§ Event Handling
§ Statements (like C / Java)
§ Operators
§ Variables global (default)
• Or local (e.g. var x = 1)
§ Types can change
• Eg. x = 1; x = ‘Hello’
§ Function definition (reuse)
§ Message Alerts
§ Page element access with Document Object Model
• Views HTML page as a tree of elements
10
5
Hello World Example
11
12
6
Application vs. Applet
§ Application
– Trusted (i.e., has full access to system resources)
– Invoked by Java Virtual Machine (JVM, java), e.g. java HelloWorld
– Should contain a main method, i.e., public static void main(String[])
§ Applet
– Not trusted (i.e., has limited access to system resource to prevent security breaches)
– Invoked automatically by the web browser
– Should be a subclass of class java.applet.Applet
13
HelloWorld.java
HelloWorldApplet.java
14
7
Java Applet Example
15
§ Java – uses Java servlets, Java Server Pages (JSP) and Java Beans.
§ Ruby on Rails – uses ruby programs and Embedded Ruby (ERB).
§ Visual Basic – Uses VB programs and Active Server Pages (ASP).
§ Others:
• PHP (Personal Home Page – originally)
• CGI (Common Gateway Interface)
• Perl (Named after the parable of the pearl)
• Python (Named for the Monty Python skits)
• Tcl (Tool Command Language)
16
8
PHP
17
§ PHP is meant to be invoked inline with content Page “escapes” into and out of a
regular html document
§ File extension is .php (was .php3 for version 3)
<html>
<head>Test page</head>
<body>
The time is now
<?php
echo date();
?>
<hr>
</body>
</html>
18
9
JSP Example
<html>
<head> <title> Hello JSP </title> </head>
<body>
<p> Hello World:
<%= new java.util.Date() %>
</p>
</body>
</html>
19
Date_jsp.java (extract)
This extract shows the part that produces the output – compare it with the JSP:
out = pageContext.getOut();
_jspx_out = out;
out.write("<html>\r\n");
out.write("<head> ");
out.write("<title> Hello JSP ");
out.write("</title> ");
out.write("</head>\r\n");
out.write("<body> \r\n");
out.write("<p> Hello World:\r\n ");
out.print( new java.util.Date() );
out.write("\r\n");
out.write("</p>\r\n");
out.write("</body>\r\n");
out.write("</html>\r\n");
20
10
Produced
21
22
11
MVC – The Model
24
25
12
MVC – The Controller
26
27
13
MVC – General Example
28
MVC Advantages
§ MVC decouples the model, view, and controller from each other to increase
flexibility and reuse.
• You can attach multiple views to the model without rewriting it.
• You can change the way a view responds to user input without changing the visual
presentation. For example, you might use a pop-up menu instead of keyboard command
keys.
29
14
3 Tier Layers vs. MVC
Business
Presentation
Database
Presentation:
§ View is the user interface (e.g. button)
§ Controller is the code (e.g. callback for button)
Data:
§ Model is the database
30
Summary
§ Client-Server Model
§ 3-Tier Architecture
§ Dynamic Web Programming Languages
§ MVC Model
31
15
email: [email protected]
Q&A
32
16