Web Technologies 2

Download Report

Transcript Web Technologies 2

Lecture 3
Web Technologies
Part 2
1
Web Technologies











HTML
XHTML
CSS
XML
JavaScript
VBSCRIPT
DOM
DHTML
AJAX
E4X
WMLScript
SQL












ASP
ADO
PHP
CGI
PERL
.NET
SMIL
SVG
FLASH
Java applets
Java servlets
Java Server page
2
What is SQL?








SQL stands for Structured Query Language
SQL allows you to access a database
SQL can execute queries against a database
SQL can retrieve data from a database
SQL can insert new records in a database
SQL can delete records from a database
SQL can update records in a database
SQL is easy to learn
3
SQL Data Manipulation Language
(DML)


SQL (Structured Query Language) is a syntax
for executing queries. But the SQL language
also includes a syntax to update, insert, and
delete records.
These query and update commands together
form the Data Manipulation Language (DML)
part of SQL:
•
•
•
•
SELECT - extracts data from a database table
UPDATE - updates data in a database table
DELETE - deletes data from a database table
INSERT INTO - inserts new data into a database
table
4
SQL Data Definition Language
(DDL)


The Data Definition Language (DDL) part of SQL
permits database tables to be created or deleted. We
can also define indexes (keys), specify links between
tables, and impose constraints between database
tables.
The most important DDL statements in SQL are:
•
•
•
•
•
CREATE TABLE - creates a new database table
ALTER TABLE - alters (changes) a database table
DROP TABLE - deletes a database table
CREATE INDEX - creates an index (search key)
DROP INDEX - deletes an index
5
SQL on the WEB



Many web applications require database at
the back side.
We can use SQL for database activities.
We use SQL together with other
technologies.
6
SQL Example with ASP
<html>
<head>
<title>My First ASP Page</title>
</head>
<body bgcolor="white" text="black">
<%
Dim adoCon
Dim rsGuestbook
Dim strSQL
'Create an ADO connection object
Set adoCon = Server.CreateObject("ADODB.Connection")
'Set an active connection to the Connection object using a DSN-less connection
adoCon.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" &
Server.MapPath("mydb.mdb")
'Create an ADO recordset object
Set rsGuestbook = Server.CreateObject("ADODB.Recordset")
'Initialise the strSQL variable with an SQL statement to query the database
strSQL = "SELECT Friends.Name, Friends.link FROM Friends;"
'Open the recordset with the SQL query
rsGuestbook.Open strSQL, adoCon
7
SQL Example with ASP
'Loop through the recordset
Do While not rsGuestbook.EOF
'Write the HTML to display the current record in the recordset
Response.Write ("<br>")
Response.Write (rsGuestbook("Name"))
Response.Write ("<br>")
Response.Write (rsGuestbook("link"))
Response.Write ("<br>")
Response.Write("Murat Koyuncu")
'Move to the next record in the recordset
rsGuestbook.MoveNext
Loop
'Reset server objects
rsGuestbook.Close
Set rsGuestbook = Nothing
Set adoCon = Nothing
%>
</body>
</html>
8
What is ASP?





ASP stands for Active Server Pages.
ASP is a program that runs inside IIS.
IIS stands for Internet Information Services.
IIS comes as a free component with
Windows Servers.
PWS is a smaller - but fully functional version of IIS (for Windows 95/98).
9
ASP Compatibility



ASP is a Microsoft Technology.
To run IIS you must have Windows NT 4.0 or
later.
To run PWS you must have Windows 95 or
later.
10
What is an ASP File?




An ASP file is just the same as an HTML file.
An ASP file can contain text, HTML, XML,
and scripts.
Scripts in an ASP file are executed on the
server.
An ASP file has the file extension ".asp“.
11
How Does ASP Differ from HTML?




When a browser requests an HTML file, the
server returns the file.
When a browser requests an ASP file, IIS
passes the request to the ASP engine.
The ASP engine reads the ASP file, line by
line, and executes the scripts in the file.
Finally, the ASP file is returned to the
browser as plain HTML.
12
What can ASP do for you?
Dynamically edit, change or add any content of a Web page.

Respond to user queries or data submitted from HTML forms.

Access any data or databases and return the results to a
browser.

Customize a Web page to make it more useful for individual
users.

The advantages of using ASP instead of CGI and Perl, are
those of simplicity and speed.

Provide security since your ASP code can not be viewed from
the browser.

Clever ASP programming can minimize the network traffic.
Important: Because the scripts are executed on the server, the
browser that displays the ASP file does not need to support
scripting at all!

13
ASP Example
<html>
<body>
<%
response.write("Hello World!")
%>
</body>
</html>
14
ASP Example-Code
<html>
<body>
<%
response.write(FormatDateTime(date(),vbgeneraldate))
response.write("<br />")
response.write(FormatDateTime(date(),vblongdate))
response.write("<br />")
response.write(FormatDateTime(date(),vbshortdate))
response.write("<br />")
response.write(FormatDateTime(now(),vblongtime))
response.write("<br />")
response.write(FormatDateTime(now(),vbshorttime))
%>
<p>
Syntax for FormatDateTime:
FormatDateTime(date,namedformat).
</p>
</body>
</html>
15
ASP Example-Output
12/10/2007
Monday, December 10, 2007
12/10/2007
9:16:58 AM
09:16
Syntax for FormatDateTime:
FormatDateTime(date,namedformat).
16
What is ADO?





ADO is a Microsoft technology.
ADO stands for ActiveX Data Objects.
ADO is a Microsoft Active-X component.
ADO is automatically installed with
Microsoft IIS.
ADO is a programming interface to access
data in a database.
17
Accessing a Database from
an ASP Page
The common way to access a database from
inside an ASP page is to:
•
•
•
•
•
•
•
Create an ADO connection to a database.
Open the database connection.
Create an ADO recordset.
Open the recordset.
Extract the data you need from the recordset.
Close the recordset.
Close the connection.
18
Create a Database
Connection
<%
set conn=Server.CreateObject
("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.
4.0"
conn.Open
"c:/webdata/northwind.mdb"
%>
19
An ODBC Connection to an
MS Access Database
Here is how to create a connection to a MS Access
Database:

Open the ODBC icon in your Control Panel.

Choose the System DSN tab.

Click on Add in the System DSN tab.

Select the Microsoft Access Driver. Click Finish.

In the next screen, click Select to locate the
database.

Give the database a Data Source Name (DSN).

Click OK.
20
An ODBC Connection to an
MS Access Database
<% set
conn=Server.CreateObject
("ADODB.Connection")
conn.Open "northwind"
%>
Name defined in
ODBC
21
Create an ADO Table
Recordset
<%
Set conn=Server.CreateObject
("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open "c:/webdata/northwind.mdb“
Set rs=Server.CreateObject
("ADODB.recordset")
rs.Open "Customers", conn
%>
22
Create an ADO SQL
Recordset
<%
Set conn=Server.CreateObject
("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0“
conn.Open "c:/webdata/northwind.mdb“
set rs=Server.CreateObject
("ADODB.recordset")
rs.Open "Select * from Customers", conn
%>
23
Extract Data from the
Recordset
<%
.....
for each x in rs.fields
response.write(x.name)
response.write(" = ")
response.write(x.value)
next
....
%>
24
ADO Example
<html>
<body>
<% set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open "c:/webdata/northwind.mdb“
set rs = Server.CreateObject("ADODB.recordset")
rs.Open "SELECT * FROM Customers", conn
do until rs.EOF
for each x in rs.Fields
Response.Write(x.name)
Response.Write(" = ")
Response.Write(x.value & "<br />")
next
Response.Write("<br />")
rs.MoveNext
loop
rs.close
conn.close %>
</body>
</html>
25
What is PHP?

PHP stands for PHP: Hypertext Preprocessor.

PHP is a server-side scripting language, like ASP.

PHP scripts are executed on the server.

PHP supports many databases (MySQL, Informix,
Oracle, Sybase,Solid,PostgreSQL,Generic ODBC, etc.)

PHP is an open source software (OSS).

PHP is free to download and use.
26
What is a PHP File?



PHP files may contain text, HTML tags and scripts.
PHP files are returned to the browser as plain
HTML.
PHP files have a file extension of ".php", ".php3",
or ".phtml"
27
Why PHP?




PHP runs on different platforms (Windows, Linux,
Unix, etc.).
PHP is compatible with almost all servers used
today (Apache, IIS, etc.).
PHP is FREE to download from the official PHP
resource: www.php.net .
PHP is easy to learn and runs efficiently on the
server side.
28
A free web server platform



Install an Apache server on a Windows
or Linux machine.
Install PHP on a Windows or Linux
machine.
Install MySQL on a Windows or Linux
machine.
29
What do PHP code look like?




PHP is a rather simple language.
Much of its syntax is borrowed from C except
for dealing with the types of variables.
You don't need to think of the types of
variables at all - you just work with their
values, not their types.
And you don't have to declare variables
before you use them.
30
A simple PHP example
<html>
<body>
<?php
echo "Hello World";
?>
</body>
</html>
31
PHP Examples
<html>
<body>
<?php $d=date("D");
if ($d=="Fri")
echo "Have a nice
weekend!";
else
echo "Have a nice
day!";
?>
</body>
</html>
<html>
<body>
<?php
for ($i=1; $i<=5; $i++) {
echo "Hello World!<br
/>"; }
?>
</body>
</html>
32
PHP Database Example
<?php
$con = mysql_connect("localhost","peter","abc123");
if (!$con)
{ die('Could not connect: ' . mysql_error()); }
mysql_select_db("my_db", $con);
$result = mysql_query("SELECT * FROM person");
while($row = mysql_fetch_array($result)) {
echo $row['FirstName'] . " " . $row['LastName'];
echo "<br />"; }
mysql_close($con);
?>
33
PHP ODBC Connection
<html>
<body>
<?php
$conn=odbc_connect('northwind','','');
if (!$conn) {exit("Connection Failed: " . $conn);}
$sql="SELECT * FROM customers";
$rs=odbc_exec($conn,$sql);
if (!$rs) {exit("Error in SQL");}
echo "<table><tr>";
echo "<th>Companyname</th>";
echo "<th>Contactname</th></tr>";
while (odbc_fetch_row($rs)) {
$compname=odbc_result($rs,"CompanyName");
$conname=odbc_result($rs,"ContactName");
echo "<tr><td>$compname</td>";
echo "<td>$conname</td></tr>"; }
odbc_close($conn);
echo "</table>"; ?>
</body>
</html>
34
What is CGI?



The Common Gateway Interface (CGI) is a
standard for interfacing external applications
with information servers, such as HTTP or
Web servers.
A plain HTML document that the Web
daemon retrieves is static, which means it
exists in a constant state: a text file that
doesn't change.
A CGI program, on the other hand, is
executed in real-time, so that it can output
dynamic information.
35
What is CGI?



For example, let's say that you wanted to "hook up"
your Unix database to the World Wide Web, to allow
people from all over the world to query it.
Basically, you need to create a CGI program that the
Web daemon will execute to transmit information to
the database engine, and receive the results back
again and display them to the client.
This is an example of a gateway, and this is where
CGI, currently version 1.1, got its origins.
36
What is CGI?

A CGI program can be written in any
language that allows it to be executed on the
system, such as:
•
•
•
•
•
•
•
C/C++
Fortran
PERL
TCL
Any Unix shell
Visual Basic
AppleScript
37
What is MS .NET

.NET is Microsoft's new Internet and Web strategy.

.NET is NOT a new operating system.

.NET is a new Internet and Web based infrastructure.

.NET delivers software as Web Services.

.NET is a framework for universal services.

.NET is a server centric computing model.

.NET will run in any browser on any platform.

.NET is based on the newest Web standards.
38
.NET Internet Standards




HTTP, the communication protocol between
Internet Applications.
XML, the format for exchanging data
between Internet Applications.
SOAP, the standard format for requesting
Web Services.
UDDI, the standard to search and discover
Web Services.
39
.NET Framework




The .NET Framework is the infrastructure for the new
Microsoft .NET Platform.
The .NET Framework contains common class
libraries - like ADO.NET, ASP.NET and Windows
Forms.
The .NET Framework is language neutral. Currently it
supports C++, C#, Visual Basic, JScript (The
Microsoft version of JavaScript) and COBOL.
The new Visual Studio.NET is a common
development environment for the new .NET
Framework.
40
.NET Framework
41
.NET Building Blocks



Web Services: Web Services provide data and
services to other applications (HTTP, HTML, XML,
and SOAP).
Internet Directory Services: .NET supports a new
kind of directory services that can answer XML based
questions about Internet Services, far more exactly
than search engines and yellow pages. These
services are built on the UDDI standard.
There are also some others…
42
.NET Software






Windows.NET: Windows 2000 and Windows XP
ASP.NET
Visual Studio.NET
Visual Basic.NET
SQL Server 2000
Internet Information Services 6.0
43
XML Based Web Protocols



SOAP: SOAP (Simple Object Access Protocol) is a
lightweight platform and language neutral
communication protocol that allows programs to
communicate via standard Internet HTTP. SOAP is
standardized by the W3C.
WSDL: WSDL (Web Services Description Language)
is an XML-based language used to define web
services and to describe how to access them. WSDL is
a suggestion by Ariba, IBM and Microsoft for
describing services for the W3C XML Activity on XML
Protocols.
UDDI: UDDI (Universal Description, Discovery and
Integration) is a directory service where businesses
can register and search for web services. UDDI is a
public registry, where one can publish and inquire
about web services.
44
Web service
45
Java Applet?

What is Java applet?

What is Java servlet?

What is JavaServer Pages?

What is Java Web Start?
46
Java Applet


An applet is a software component that runs
in the context of another program, for
example a web browser.
A Java applet is an applet delivered in the
form of Java bytecode. Java applets can run
in a Web browser using a Java Virtual
Machine (JVM), or in Sun's AppletViewer, a
stand-alone tool for testing applets.
47
Java Applet



Java applets are usually written in the Java
programming language but they can also be
written in other languages that compile to
Java bytecode.
Applets are used to provide interactive
features to web applications that cannot be
provided by HTML.
Since Java's bytecode is platform
independent, Java applets can be executed
by browsers for many platforms, including
Windows, Unix, Mac OS and Linux.
48
Java bytecode



Java bytecode is the form of instructions that the
Java virtual machine executes.
Each bytecode instruction is one byte in length.
Code:
•
•
•
•
•
•
•
•
•
•
•
0: iconst_2
1: istore_1
2: iload_1
3: sipush 1000
6: if_icmpge 44
9: iconst_2
10: istore_2
11: iload_2
12: iload_1
41: goto 2
44: return
49
What Is a Servlet?

Web server response can be static or dynamic
•
•

Static: HTML document is retrieved from the file
system and returned to the client
Dynamic: HTML document is generated by a
program in response to an HTTP request
Java servlets are one technology for producing
dynamic server responses
•
Servlet is a class instantiated by the server to
produce a dynamic response
50
Servlet Overview
51
Servlet Example
52
Servlet Example
53
Servlets vs. Java Applications

Servlets do not have a main()
•
•

Servlet interaction with end user is indirect
via request/response object APIs
•

The main() is in the server
Entry point to servlet code is via call to a
method (doGet() in the example)
Actual HTTP request/response processing is
handled by the server
Primary servlet output is typically HTML
54
Running Servlets
Simple way to run a servlet:
1. Compile servlet (make sure that JWSDP libraries
are on path)
2. Copy .class file to shared/classes directory
3. (Re)start the Tomcat web server
4. If the class is named ServletHello, browse to
http://localhost:8080/servlet/ServletHello
55
What is JSP?




Short for Java Server Page.
A server-side technology.
Java Server Pages are an extension to the
Java servlet technology that was developed
by Sun.
JSPs have dynamic scripting capability that
works in tandem with HTML code.
56
What is JSP?




The JSP syntax adds additional XML-like
tags, called JSP actions, to be used to invoke
built-in functionality.
A JSP compiler may generate a servlet in
Java code that is then compiled by the Java
compiler, or it may generate byte code for the
servlet directly.
Compilation occurs the first time the
application is run.
A JSP Compiler is triggered by the .jsp file
name extension in a URL.
57
JSP Example
<%@ page errorPage="myerror.jsp" %>
<%@ page import="com.foo.bar" %>
<html>
<head>
<%! int serverInstanceVariable = 1;%>
...
<% int localStackBasedVariable = 1; %>
<table>
<tr>
<td><%= toStringOrBlank( "expanded
inline data " + 1 ) %></td>
</tr> ...
58
JSP vs. Pure Servlets.



JSP doesn't give you anything that you
couldn't in principle do with a servlet.
But it is more convenient to write (and to
modify!).
By separating the look from the content you
can put different people on different tasks:
your Web page design experts can build the
HTML, leaving places for your servlet
programmers to insert the dynamic content.
59
JSP vs ASP


It was originally created as an alternative to
Microsoft's ASPs (Active Server Pages).
Recently, however, Microsoft has countered
JSP technology with its own ASP.NET, part
of the .NET initiative.
60
JSP vs. Active Server Pages
(ASP).

ASP is a similar technology from Microsoft.

The advantages of JSP are twofold.
•
•
First, the dynamic part is written in Java, not
Visual Basic or other MS-specific language, so
it is more powerful and easier to use.
Second, it is portable to other operating
systems and non-Microsoft Web servers.
61
JSP vs. JavaScript.



JavaScript can generate HTML dynamically
on the client.
This is a useful capability, but only handles
situations where the dynamic information is
based on the client's environment.
Since it runs on the client, JavaScript can't
access server-side resources like databases,
catalogs, pricing information, and the like.
62
What is Java Web Start?





Sun’s tool for installing Java applications and
updates.
It can also distribute Applets.
They automatically install and hook
themselves up to the Java runtime.
All you have to do is click an icon with your
browser to use them.
Java Web Start makes it easy for users to
install Java apps once they have a web start
enabled browser, or the web start app
installed.
63
What is Java Web Start?




Java Web Start is a framework developed by Sun
Microsystems which allows application software for
the Java Platform to be started directly from the
Internet using a web browser.
Unlike Java applets, Web Start applications do not run
inside the browser.
One chief advantage of Web Start over applets is that
they overcome many compatibility problems with
browsers' Java plugins and different JVM versions.
On the other hand, Web Start programs cannot
communicate with the browser as easily as applets.
64
End of Lecture 3
65