65
1 Lecture 3 Web Technologies Part 2

1 Lecture 3 Web Technologies Part 2. 2 l HTML l XHTML l CSS l XML l JavaScript l VBSCRIPT DOM l DHTML l AJAX l E4X l WMLScript l SQL Web Technologies

Embed Size (px)

Citation preview

Page 1: 1 Lecture 3 Web Technologies Part 2. 2 l HTML l XHTML l CSS l XML l JavaScript l VBSCRIPT DOM l DHTML l AJAX l E4X l WMLScript l SQL Web Technologies

1

Lecture 3

Web TechnologiesPart 2

Page 2: 1 Lecture 3 Web Technologies Part 2. 2 l HTML l XHTML l CSS l XML l JavaScript l VBSCRIPT DOM l DHTML l AJAX l E4X l WMLScript l SQL Web Technologies

2

HTML XHTML CSS XML JavaScript VBSCRIPT

DOM DHTML AJAX E4X WMLScript SQL

Web Technologies

ASP ADO PHP CGI PERL .NET SMIL SVG FLASH Java applets Java servlets Java Server page

Page 3: 1 Lecture 3 Web Technologies Part 2. 2 l HTML l XHTML l CSS l XML l JavaScript l VBSCRIPT DOM l DHTML l AJAX l E4X l WMLScript l SQL Web Technologies

3

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

Page 4: 1 Lecture 3 Web Technologies Part 2. 2 l HTML l XHTML l CSS l XML l JavaScript l VBSCRIPT DOM l DHTML l AJAX l E4X l WMLScript l SQL Web Technologies

4

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

Page 5: 1 Lecture 3 Web Technologies Part 2. 2 l HTML l XHTML l CSS l XML l JavaScript l VBSCRIPT DOM l DHTML l AJAX l E4X l WMLScript l SQL Web Technologies

5

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

Page 6: 1 Lecture 3 Web Technologies Part 2. 2 l HTML l XHTML l CSS l XML l JavaScript l VBSCRIPT DOM l DHTML l AJAX l E4X l WMLScript l SQL Web Technologies

6

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.

Page 7: 1 Lecture 3 Web Technologies Part 2. 2 l HTML l XHTML l CSS l XML l JavaScript l VBSCRIPT DOM l DHTML l AJAX l E4X l WMLScript l SQL Web Technologies

7

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 objectSet adoCon = Server.CreateObject("ADODB.Connection")

'Set an active connection to the Connection object using a DSN-less connectionadoCon.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" &

Server.MapPath("mydb.mdb")

'Create an ADO recordset objectSet rsGuestbook = Server.CreateObject("ADODB.Recordset")

'Initialise the strSQL variable with an SQL statement to query the databasestrSQL = "SELECT Friends.Name, Friends.link FROM Friends;"

'Open the recordset with the SQL query rsGuestbook.Open strSQL, adoCon

Page 8: 1 Lecture 3 Web Technologies Part 2. 2 l HTML l XHTML l CSS l XML l JavaScript l VBSCRIPT DOM l DHTML l AJAX l E4X l WMLScript l SQL Web Technologies

8

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 objectsrsGuestbook.CloseSet rsGuestbook = NothingSet adoCon = Nothing%>

</body></html>

Page 9: 1 Lecture 3 Web Technologies Part 2. 2 l HTML l XHTML l CSS l XML l JavaScript l VBSCRIPT DOM l DHTML l AJAX l E4X l WMLScript l SQL Web Technologies

9

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).

Page 10: 1 Lecture 3 Web Technologies Part 2. 2 l HTML l XHTML l CSS l XML l JavaScript l VBSCRIPT DOM l DHTML l AJAX l E4X l WMLScript l SQL Web Technologies

10

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.

Page 11: 1 Lecture 3 Web Technologies Part 2. 2 l HTML l XHTML l CSS l XML l JavaScript l VBSCRIPT DOM l DHTML l AJAX l E4X l WMLScript l SQL Web Technologies

11

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“.

Page 12: 1 Lecture 3 Web Technologies Part 2. 2 l HTML l XHTML l CSS l XML l JavaScript l VBSCRIPT DOM l DHTML l AJAX l E4X l WMLScript l SQL Web Technologies

12

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.

Page 13: 1 Lecture 3 Web Technologies Part 2. 2 l HTML l XHTML l CSS l XML l JavaScript l VBSCRIPT DOM l DHTML l AJAX l E4X l WMLScript l SQL Web Technologies

13

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!

Page 14: 1 Lecture 3 Web Technologies Part 2. 2 l HTML l XHTML l CSS l XML l JavaScript l VBSCRIPT DOM l DHTML l AJAX l E4X l WMLScript l SQL Web Technologies

14

ASP Example

<html>

<body>

<%response.write("Hello World!")

%>

</body>

</html>

Page 15: 1 Lecture 3 Web Technologies Part 2. 2 l HTML l XHTML l CSS l XML l JavaScript l VBSCRIPT DOM l DHTML l AJAX l E4X l WMLScript l SQL Web Technologies

15

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>

Page 16: 1 Lecture 3 Web Technologies Part 2. 2 l HTML l XHTML l CSS l XML l JavaScript l VBSCRIPT DOM l DHTML l AJAX l E4X l WMLScript l SQL Web Technologies

16

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).

Page 17: 1 Lecture 3 Web Technologies Part 2. 2 l HTML l XHTML l CSS l XML l JavaScript l VBSCRIPT DOM l DHTML l AJAX l E4X l WMLScript l SQL Web Technologies

17

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.

Page 18: 1 Lecture 3 Web Technologies Part 2. 2 l HTML l XHTML l CSS l XML l JavaScript l VBSCRIPT DOM l DHTML l AJAX l E4X l WMLScript l SQL Web Technologies

18

Accessing a Database from an ASP Page

The common way to access a database frominside 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.

Page 19: 1 Lecture 3 Web Technologies Part 2. 2 l HTML l XHTML l CSS l XML l JavaScript l VBSCRIPT DOM l DHTML l AJAX l E4X l WMLScript l SQL Web Technologies

19

Create a Database Connection

<%

set conn=Server.CreateObject ("ADODB.Connection")

conn.Provider="Microsoft.Jet.OLEDB.4.0"

conn.Open "c:/webdata/northwind.mdb"

%>

Page 20: 1 Lecture 3 Web Technologies Part 2. 2 l HTML l XHTML l CSS l XML l JavaScript l VBSCRIPT DOM l DHTML l AJAX l E4X l WMLScript l SQL Web Technologies

20

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.

Page 21: 1 Lecture 3 Web Technologies Part 2. 2 l HTML l XHTML l CSS l XML l JavaScript l VBSCRIPT DOM l DHTML l AJAX l E4X l WMLScript l SQL Web Technologies

21

An ODBC Connection to an MS Access Database

<% set

conn=Server.CreateObject

("ADODB.Connection")

conn.Open "northwind"

%>

Name defined in ODBC

Page 22: 1 Lecture 3 Web Technologies Part 2. 2 l HTML l XHTML l CSS l XML l JavaScript l VBSCRIPT DOM l DHTML l AJAX l E4X l WMLScript l SQL Web Technologies

22

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 %>

Page 23: 1 Lecture 3 Web Technologies Part 2. 2 l HTML l XHTML l CSS l XML l JavaScript l VBSCRIPT DOM l DHTML l AJAX l E4X l WMLScript l SQL Web Technologies

23

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%>

Page 24: 1 Lecture 3 Web Technologies Part 2. 2 l HTML l XHTML l CSS l XML l JavaScript l VBSCRIPT DOM l DHTML l AJAX l E4X l WMLScript l SQL Web Technologies

24

Extract Data from the Recordset

<%.....for each x in rs.fields

response.write(x.name) response.write(" = ") response.write(x.value)

next ....%>

Page 25: 1 Lecture 3 Web Technologies Part 2. 2 l HTML l XHTML l CSS l XML l JavaScript l VBSCRIPT DOM l DHTML l AJAX l E4X l WMLScript l SQL Web Technologies

25

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

looprs.close conn.close %>

</body> </html>

Page 26: 1 Lecture 3 Web Technologies Part 2. 2 l HTML l XHTML l CSS l XML l JavaScript l VBSCRIPT DOM l DHTML l AJAX l E4X l WMLScript l SQL Web Technologies

26

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.

Page 27: 1 Lecture 3 Web Technologies Part 2. 2 l HTML l XHTML l CSS l XML l JavaScript l VBSCRIPT DOM l DHTML l AJAX l E4X l WMLScript l SQL Web Technologies

27

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"

Page 28: 1 Lecture 3 Web Technologies Part 2. 2 l HTML l XHTML l CSS l XML l JavaScript l VBSCRIPT DOM l DHTML l AJAX l E4X l WMLScript l SQL Web Technologies

28

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.

Page 29: 1 Lecture 3 Web Technologies Part 2. 2 l HTML l XHTML l CSS l XML l JavaScript l VBSCRIPT DOM l DHTML l AJAX l E4X l WMLScript l SQL Web Technologies

29

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.

Page 30: 1 Lecture 3 Web Technologies Part 2. 2 l HTML l XHTML l CSS l XML l JavaScript l VBSCRIPT DOM l DHTML l AJAX l E4X l WMLScript l SQL Web Technologies

30

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.

Page 31: 1 Lecture 3 Web Technologies Part 2. 2 l HTML l XHTML l CSS l XML l JavaScript l VBSCRIPT DOM l DHTML l AJAX l E4X l WMLScript l SQL Web Technologies

31

A simple PHP example

<html>

<body>

<?php

echo "Hello World";

?>

</body>

</html>

Page 32: 1 Lecture 3 Web Technologies Part 2. 2 l HTML l XHTML l CSS l XML l JavaScript l VBSCRIPT DOM l DHTML l AJAX l E4X l WMLScript l SQL Web Technologies

32

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>

Page 33: 1 Lecture 3 Web Technologies Part 2. 2 l HTML l XHTML l CSS l XML l JavaScript l VBSCRIPT DOM l DHTML l AJAX l E4X l WMLScript l SQL Web Technologies

33

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); ?>

Page 34: 1 Lecture 3 Web Technologies Part 2. 2 l HTML l XHTML l CSS l XML l JavaScript l VBSCRIPT DOM l DHTML l AJAX l E4X l WMLScript l SQL Web Technologies

34

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>

Page 35: 1 Lecture 3 Web Technologies Part 2. 2 l HTML l XHTML l CSS l XML l JavaScript l VBSCRIPT DOM l DHTML l AJAX l E4X l WMLScript l SQL Web Technologies

35

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.

Page 36: 1 Lecture 3 Web Technologies Part 2. 2 l HTML l XHTML l CSS l XML l JavaScript l VBSCRIPT DOM l DHTML l AJAX l E4X l WMLScript l SQL Web Technologies

36

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.

Page 37: 1 Lecture 3 Web Technologies Part 2. 2 l HTML l XHTML l CSS l XML l JavaScript l VBSCRIPT DOM l DHTML l AJAX l E4X l WMLScript l SQL Web Technologies

37

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

Page 38: 1 Lecture 3 Web Technologies Part 2. 2 l HTML l XHTML l CSS l XML l JavaScript l VBSCRIPT DOM l DHTML l AJAX l E4X l WMLScript l SQL Web Technologies

38

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.

Page 39: 1 Lecture 3 Web Technologies Part 2. 2 l HTML l XHTML l CSS l XML l JavaScript l VBSCRIPT DOM l DHTML l AJAX l E4X l WMLScript l SQL Web Technologies

39

.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.

Page 40: 1 Lecture 3 Web Technologies Part 2. 2 l HTML l XHTML l CSS l XML l JavaScript l VBSCRIPT DOM l DHTML l AJAX l E4X l WMLScript l SQL Web Technologies

40

.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.

Page 41: 1 Lecture 3 Web Technologies Part 2. 2 l HTML l XHTML l CSS l XML l JavaScript l VBSCRIPT DOM l DHTML l AJAX l E4X l WMLScript l SQL Web Technologies

41

.NET Framework

Page 42: 1 Lecture 3 Web Technologies Part 2. 2 l HTML l XHTML l CSS l XML l JavaScript l VBSCRIPT DOM l DHTML l AJAX l E4X l WMLScript l SQL Web Technologies

42

.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…

Page 43: 1 Lecture 3 Web Technologies Part 2. 2 l HTML l XHTML l CSS l XML l JavaScript l VBSCRIPT DOM l DHTML l AJAX l E4X l WMLScript l SQL Web Technologies

43

.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

Page 44: 1 Lecture 3 Web Technologies Part 2. 2 l HTML l XHTML l CSS l XML l JavaScript l VBSCRIPT DOM l DHTML l AJAX l E4X l WMLScript l SQL Web Technologies

44

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.

Page 45: 1 Lecture 3 Web Technologies Part 2. 2 l HTML l XHTML l CSS l XML l JavaScript l VBSCRIPT DOM l DHTML l AJAX l E4X l WMLScript l SQL Web Technologies

45

Web service

Page 46: 1 Lecture 3 Web Technologies Part 2. 2 l HTML l XHTML l CSS l XML l JavaScript l VBSCRIPT DOM l DHTML l AJAX l E4X l WMLScript l SQL Web Technologies

46

What is Java applet?

What is Java servlet?

What is JavaServer Pages?

What is Java Web Start?

Java Applet?

Page 47: 1 Lecture 3 Web Technologies Part 2. 2 l HTML l XHTML l CSS l XML l JavaScript l VBSCRIPT DOM l DHTML l AJAX l E4X l WMLScript l SQL Web Technologies

47

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.

Page 48: 1 Lecture 3 Web Technologies Part 2. 2 l HTML l XHTML l CSS l XML l JavaScript l VBSCRIPT DOM l DHTML l AJAX l E4X l WMLScript l SQL Web Technologies

48

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.

Page 49: 1 Lecture 3 Web Technologies Part 2. 2 l HTML l XHTML l CSS l XML l JavaScript l VBSCRIPT DOM l DHTML l AJAX l E4X l WMLScript l SQL Web Technologies

49

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

Page 50: 1 Lecture 3 Web Technologies Part 2. 2 l HTML l XHTML l CSS l XML l JavaScript l VBSCRIPT DOM l DHTML l AJAX l E4X l WMLScript l SQL Web Technologies

50

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

Page 51: 1 Lecture 3 Web Technologies Part 2. 2 l HTML l XHTML l CSS l XML l JavaScript l VBSCRIPT DOM l DHTML l AJAX l E4X l WMLScript l SQL Web Technologies

51

Servlet Overview

Page 52: 1 Lecture 3 Web Technologies Part 2. 2 l HTML l XHTML l CSS l XML l JavaScript l VBSCRIPT DOM l DHTML l AJAX l E4X l WMLScript l SQL Web Technologies

52

Servlet Example

Page 53: 1 Lecture 3 Web Technologies Part 2. 2 l HTML l XHTML l CSS l XML l JavaScript l VBSCRIPT DOM l DHTML l AJAX l E4X l WMLScript l SQL Web Technologies

53

Servlet Example

Page 54: 1 Lecture 3 Web Technologies Part 2. 2 l HTML l XHTML l CSS l XML l JavaScript l VBSCRIPT DOM l DHTML l AJAX l E4X l WMLScript l SQL Web Technologies

54

Servlets vs. Java Applications

Servlets do not have a main()• The main() is in the server• Entry point to servlet code is via call to a

method (doGet() in the example) Servlet interaction with end user is indirect

via request/response object APIs• Actual HTTP request/response processing is

handled by the server Primary servlet output is typically HTML

Page 55: 1 Lecture 3 Web Technologies Part 2. 2 l HTML l XHTML l CSS l XML l JavaScript l VBSCRIPT DOM l DHTML l AJAX l E4X l WMLScript l SQL Web Technologies

55

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 tohttp://localhost:8080/servlet/ServletHello

Page 56: 1 Lecture 3 Web Technologies Part 2. 2 l HTML l XHTML l CSS l XML l JavaScript l VBSCRIPT DOM l DHTML l AJAX l E4X l WMLScript l SQL Web Technologies

56

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.

Page 57: 1 Lecture 3 Web Technologies Part 2. 2 l HTML l XHTML l CSS l XML l JavaScript l VBSCRIPT DOM l DHTML l AJAX l E4X l WMLScript l SQL Web Technologies

57

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.

Page 58: 1 Lecture 3 Web Technologies Part 2. 2 l HTML l XHTML l CSS l XML l JavaScript l VBSCRIPT DOM l DHTML l AJAX l E4X l WMLScript l SQL Web Technologies

58

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> ...

Page 59: 1 Lecture 3 Web Technologies Part 2. 2 l HTML l XHTML l CSS l XML l JavaScript l VBSCRIPT DOM l DHTML l AJAX l E4X l WMLScript l SQL Web Technologies

59

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.

Page 60: 1 Lecture 3 Web Technologies Part 2. 2 l HTML l XHTML l CSS l XML l JavaScript l VBSCRIPT DOM l DHTML l AJAX l E4X l WMLScript l SQL Web Technologies

60

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.

Page 61: 1 Lecture 3 Web Technologies Part 2. 2 l HTML l XHTML l CSS l XML l JavaScript l VBSCRIPT DOM l DHTML l AJAX l E4X l WMLScript l SQL Web Technologies

61

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.

Page 62: 1 Lecture 3 Web Technologies Part 2. 2 l HTML l XHTML l CSS l XML l JavaScript l VBSCRIPT DOM l DHTML l AJAX l E4X l WMLScript l SQL Web Technologies

62

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.

Page 63: 1 Lecture 3 Web Technologies Part 2. 2 l HTML l XHTML l CSS l XML l JavaScript l VBSCRIPT DOM l DHTML l AJAX l E4X l WMLScript l SQL Web Technologies

63

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.

Page 64: 1 Lecture 3 Web Technologies Part 2. 2 l HTML l XHTML l CSS l XML l JavaScript l VBSCRIPT DOM l DHTML l AJAX l E4X l WMLScript l SQL Web Technologies

64

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.

Page 65: 1 Lecture 3 Web Technologies Part 2. 2 l HTML l XHTML l CSS l XML l JavaScript l VBSCRIPT DOM l DHTML l AJAX l E4X l WMLScript l SQL Web Technologies

65

End of Lecture 3