ITY276 presentation 3 - University Of Worcester

Download Report

Transcript ITY276 presentation 3 - University Of Worcester

COMP3121
E-Business Technologies
Richard Henson
University of Worcester
October 2010
Week 3 – Early Web Applications
and scope for E-commerce

Objectives:
 Compare and contrast embedded code for clientonly applications & server scripting
 Explain how JavaScript relates to Sun Java, and
why JavaScript is the preferred language for many
Internet developers
 Explain how VBScript can to be used in serverscripting, and why it has fallen out of favour
 Set up a software development environment for
producing client-server websites with remote
database support
Client-side: going beyond HTML…

HTML cannot do everything!
 sequence of code…
 not a programming language

Tim Berners-Lee based it on SGML - a
formatting language
 never intended to be for programming
 doesn’t allow definition of new “objects” (need a
more flexible language like XML)

Programming languages also deal with:
 selection (choice from different code sequences)
 iteration (repeating the same code again and again)
Introducing Selection and Iteration
into a HTML document

All about embedding programming code into
a HTML file
 generally, embedded code is included in <head>
 sometimes, a chunk of code included within
<body>

Normally… programming functions
 defined in <head>
 called from the within <body>

As previously explained, languages used:
 Visual BASIC (as VBScript)
 Java (as JavaScript)
Rapid Generation of Clientside embedded code

Apart from writing the code for yourself…
 cut-and-paste from one of the many sites on the
Internet offering free (or paid for) code

Alternatively, a tool could be used to generate
the code at the click of a button:
 e.g. Dreamweaver or Visual Studio

This is fine for one-off use, but could cause
problems e.g.:
 reusing/modifying the code in a different context
 don’t understand what the code is doing…
Interpreted and Compiled
Languages


Programming (source) code must be
converted into “machine code” before it can
be understood and acted on by the CPU
This can be done in two ways:
 convert whole program (using a compiler) and
save it in a file
 leave program as it is, and convert it (using an
interpreter) one line at a time when it is needed

Compiled code generally occupies much more
space than source code
 so of more limited use on the Internet (esp. early
days)...
How do Browsers cope with
source code?

Designed to use interpretation on HTML
code
 reads one line of HTML key words and their
parameters and uses HTML interpreter to convert
(or interpret) that line into CPU instructions
 reads & interprets next line… and so on…
 CPU does further processing and sends
commands to the video card which creates the
visual display
Java Programming Language

Developed by Sun Microsystems
 intention of combining best features of two most
popular languages:
» “C” (compiled language)
» BASIC (generally an interpreted language - although run-time
versions are available)

Used in two different ways:
 Applets - small pieces of code that can fit into
other programs (e.g. HTML documents)
 Programs - like C programs but generally more
compact (source code takes up less space than
compiled code)
An Instant Use for Java…

In 1994:
the network companies weren’t interested
in browser power…
» network managers concerned with controlling
users!!
» applets offered far too much user control
the Internet (thanks to the Tim and the
Web) was evolving in a different direction…
» all about “freedom” for the user
» what Java offered would enrich this…
Day of Enlightenment?

Quote from Sun’s own website:
“… Daily, momentum behind the new vision
grew.
WebRunner [early Java application named after BladeRunner] was just a
demo, but an impressive one:
It brought to life, for the first time,
animated, moving objects and dynamic
executable content inside a Web browser.
That had never been done.”
Integration of Java and Netscape

Subsequent to WebRunner demo...
Java code started being used to animate
objects displayed on a Netscape browser

BIG breakthrough…
The Internet now had the potential to rival
television as a mass medium!
Netscape and Sun joined forces
 Shares in both companies skyrocketed!

JavaScript and JScript

Early 1995:
 Sun and Netscape released JavaScript
 JavaScript interpreter included with Netscape browser

Microsoft (nearly too late!) saw they were being
usurped
 Windows 95 delayed, and became Internet ready with
language interpretation beyond HTML almost as an
afterthought…
 developers very busy in 1996!
» came up with JScript… and ActiveX

Netscape & Sun infuriated about JScript
 refused to include support in their browser!
» “Browser wars” began...
 eventually, Microsoft withdrew JScript and concentrated on
developing C into C#
History of Visual BASIC


Microsoft’s first success was putting BASIC
into a micro as a 32K ROM (1976-7)
“Visual” BASIC evolved in early 1990s
 derisory comments by purists
 increasingly popular with (some) developers…

Gates responded to criticisms that earlier
versions of BASIC lacked programming
structure
 Visual BASIC to some extent object-orientated
 interface developments made it very flexible to use
 but… ultimately, it was still BASIC…
What is VBScript?

Scaled down version of Visual Basic
no operating system calls
Provides a powerful, easy to learn tool
that can be used to add interaction to
web pages
 For developers experienced in VB or
VBA (Visual Basic for Applications),
transition to VBScript is straightforward

should be immediately productive!
What is ActiveX®?

A more successful Microsoft invention…
 started out as “compiled” (i.e. “run-time”) VB code

Known as a “control”
 contains NO source code so can’t be embedded
in HTML, but can be called from a HTML file
 allows compiled (i.e. executable) code to talk to
host applications
 difficult to “hack” the code if source code not
available

As the scripts are compiled into executable
versions the source language is therefore
irrelevant
 languages other than VB can be used…
Client-Server web applications
& Server Scripts
 Client-server web applications usually
require:
1. a web server, for interpreting or compiling then
processing the scripts
2. a server-end database to provide and store data
3. physical & logical connections between serverscripts, client-end input forms and server-end
database
4. clearly defined locations for gathering input data
at client-end, for server scripts, and for
database(s)
Writing Server Scripts

Server code can be embedded directly into
the body of the web page
 A Command is needed to inform the browser
» (1) that non-HTML code is about to be used
» (2) when next code reverts to HTML

With .asp scripts…
 the command to start the script is <%
 to end the script… %>

With .php scripts…
 <?php starts the script
 ?> ends the script
Server Scripts and “Localhost”


No matter which scripting type is used, the
code can be tested locally on a computer
running a web server that can understand that
type of script
The secret is to use “localhost” in the URL at
the browser window
 (localhost = path to the server scripting root folder)


A typical URL for testing such a script
(scriptname.aspx) locally could then be:
http://localhost/scriptname.aspx
Using Software Tools for
Client-Server Development


“localhost” maps directly to the home folder
configured on the local web server
It is therefore possible to have “local site” (page
development) and “remote site” (script testing on
server) both happening on the same machine. Tools
can be configured to allow
 easy “local site” and “remote site” management including up
& downloading
 server scripts to run directly without having to use localhost
to check each time
 the creation of server scripts in a number of different
formats (asp, asp.net, php, etc…)
Development of .NET
framework for Server Scripting

BASIC and VB were very much a part of Microsoft’s strategy,
until circa 1999/2000 when the use of raw source code became
a security issue
 Gates realised that e-business and e-commerce would never be
reliable without using secure (and therefore compiled) code
 Microsoft rejected their previous strategy which used source VB
code and an interpreter program within IIS

Result: .net Framework & ASP.NET:
 VB evolved into the more object oriented (and complied) VB.NET

Server equivalent of ActiveX controls could now be
used/developed for the server end…
 basis for
» .net server-side controls
» the ubiquitous use of compiled languages
Similarities between
ASP and ASP.NET scripts

Despite fundamental differences between asp and
aspx scripts, IIS v5 (released in 2001, for Windows
XP) was designed so these script types could run
side by side on the IIS platform:
 asp: IIS executes scripts through ADO objects and a VB
interpreter
 aspx: uses .net framework on top of IIS:
» ignores .asp files
» “by default” (can be changed) uses the same default scripts
folder as asp to execute aspx files

Microsoft expected developers to switch to aspx…
but many asp applications continue to exist, and VB
developers continue to develop them, to present day!
Advantages of ASP.NET scripts
compared to ASP

Asp.net code:
 is compiled, not interpreted
» v1 relied on an additional /bin folder for deployed
“assemblies” or “controls” containing executable code
» v2 onwards used /app_code folder – latter more flexible; could
be referred to directly from a site configuration file
 uses xml-type tags
 can be written using a variety of programming
languages
» language declared at beginning of file
 is full object-oriented and can easily be used as
“controls” to respond to on-screen “events”
Running controls with ASP.NET

Microsoft developed an “intermediate
language” (IL) for .net framework
 could be readily converted into machine code
but the IL not easily hacked

Source code for .net development can be
written in any language that can be
translated into IL
 VB.NET builds on existing practice from asp
 C# has proved to be most popular with
developers, many of whom had previously used
“C” and C++
» why use VB.net, when you can use C!?
Components of the evolving
.net framework

.net common language infrastructure (CLI)
 “managed execution” framework for scripts
 runs Intel x86 IL code
» common Language run-time (CLR) for executing controls
» ready to run; development language irrelevant

Besides /bin folder for “assemblies” & executables,
v1 .net framework web applications also must have:
 a web.config file

 (store of configuration info e.g. a path to database file)
As well as app_data, .net apps from v2 onwards also support
the following additional folders:
 , app_code, app_browsers, app_themes, app_localresources,
app_globalresources, app_webreferences
 app_code preferred over “bin” for compiled assemblies
How the .net environment
manages an application


“Assemblies” from .aspx files added to /bin
CLI executes IL assemblies as CLR (runtime)
 just a set of Win32 DLLs created by compiling the
assembly components
» written in IL
» makes sure script execution is “controlled” and kept within
boundaries
» an earlier version of IIS used to “leak” memory until the
system needed rebooting
 usually loaded implicitly when a .net application is
run
Mechanism of Loading
Assemblies for processing
“AppDomain” sets up a security
boundary in memory for each
application
 Code (.exe, or .dll) loaded into process
“spaceperfo”
 JIT compilation ensures “flat out
performance”

cf Wallace & Grommit – latter lays out the
track as the train is about to pass along it
HTTP processing

.net architecture designed “with failure in mind”
 overall control with http.sys
 if memory usage gets too large, .net pulled down and
restarted…

Each AppDomain uses a pipeline of objects to handle
requests





Httpapplication – oversees flow
Httpcontext – tracks “per request” state
Modules – generic “pluggable services
Handlers – http requests
Covers most (all?) eventualities and makes sure
requests are correctly dealt with – no muddling of
threads (!)
Very Useful ASP.net components:
1. Web Controls

Reusable classes used to render parts
of a page
Similar to Windows “forms”

New control created for each request
» view state/Event tracking handled automatically

A typical web page may have a
hierarchical structure of web controls to
makes them easily manageable
Very Useful ASP.net components:
2. Event Handlers

HTTP is stateless (no data retention)
 no multi-step processes possible
 e.g. HTML form contents disappear once form
submitted

Web Controls provide scope for handling
events, when triggered (or raised)
 e.g. Page_Load, OnClick
 “PostBack architecture”
 allows web forms data to reappear on the screen
Very Useful ASP.net components:
3. Master Pages & Themes

Master Page
 resides in .master file
 defines template for other pages
» cf powerpoint slide master
 Contains top <html>, <body>, <form> tags
 “Page” command utilises master either “static” or “dynamic”
 “Page_init” process renders components

Themes
 allow common styles to be applied across a series of pages

Developers can still use .CSS files
 fully supported by the master file and page “themes”
concepts
.net Development and RAD tools

By now, you may be thinking…
 “Help! I can’t program in “C”!”

DON’T BE SCARED!
 the syntax of object-oriented C# is similar to Java
 RAD tools such as Dreamweaver (earlier
versions) and Visual Web Developer provide a
range of web controls already written in C#
 Extension Managers enable other controls to be
added to the RAD environment

RAD tools also help with
 putting controls/assemblies into the /bin or
/app_code folder
 setting up the web.config file
Reading/Writing to data store

The programming language defines the data
structure for any data being written to a file

Could be very simple






e.g. CSV (fields separated by commas)
saved as a stream of text
flatfile, no relations
consequent limited scope for searching and selectively extracting
data
The VB6 Practical exercise in the previous session
(orderform.html & asp) used such an approach…
In practice, relational databases are normally used to
store data
 need proper connectivity software!
 RAD environments make establishing connectivity with
relational databases just as easy with asp.net as it was with
asp
Relational Databases

Much more complex than “flat” text files…
 but a tight structure means existing data can be
more easily located…


Real advantage of a true relational database is
that SQL can be used for r/w & query database
operations
To make a two-way link, it is just necessary to:
 make relevant Microsoft data access components
(MDAC) available
 define “recordsets” (asp) or “datasets” (aspx) using a
programming language & embedded SQL
 provide connectivity link to database pathname
Database Design

Same principles apply as with any other relational
database management system (RDBMS)…
 identify entities & attributes
 produce entity relationship
» define logic relationships between entities
 make sure data is fully normalised
» create tables & links
 use embedded SQL statements in the server script to
communicate with the data:
» extract data from specific fields in particular tables
» put data into specific fields in particular tables

However, some “self-taught” developers will be
unaware of this, and try to build the data round the
processing…
Evolution of Application
- RDBMS connectivity

In the early web development days…
 for the connection of an application to a relational
databases…
 a client application had to be written to use the
proprietary API (application program interface)

Even then, there was a problem:
 what if more than one RDBMS needs to be used?

The solution would be to use several different
APIs
 each needed a client application…
 added greatly to the complexity of the task!
The Microsoft Solution:
the ODBC API

Aspiration: the “Universal Data Access” (UDA) model
 all data consumers interact with all data providers…
 response to the “API for each application” problem


First stage: ODBC = Open Database Connectivity
Developed in early 1990s:
 common API for writing applications to access ANY relational
DBMS for which an ODBC driver had been written

Once the APIs had all been written, tried, and
tested…
 any relational database with an ODBC compliant interface
could use them
 DSN model offered easy database path connectivity string
management
ActiveX

The next stage in evolution of Microsoft’s data
objects model
 sexy name for OLE v2.0
 made up of…
» OLE

Object Linking and Embedding…
» Combined with COM


Common Object Model
ActiveX Data Objects make up a series of
modular components called ADO
 used for “run-time” web applications
 basis of .net controls
More about VB ActiveX
Data Objects (ADO)

Designed to simplify the writing of client
applications to access data sources
through OLE DB providers
 even more flexible than DSN which had to be
specified on the local machine and was limited
to the ODBC providers on that machine


use a common, easy-to-use object model
data sources can now also include:
 spreadsheets
 graphics
 web pages
OLE DB

Application of OLE/ActiveX principles to
connectivity between applications and
databases
to be more precise, and relational
database management systems

An interface specification that provides
a layer of abstraction between:
a data provider e.g. relational DBMS
a data consumer e.g. business object or
client application
Universal Data Access in practice
System Connection
to the Database

Provided by Microsoft Data Access
Components (MDAC)
 easily downloaded:
» www.microsoft.com/data/download_21242023.htm

Once the correct components have been
chosen…
 for scripts on a web server to be able to talk with a
relational database, a logical 'connection' needs to
be set up on the local system
 Must include:
» a definition of where the database is
» a few simple rules on how the database should be treated
Making a connection to a
database on the web server

Two systems still popular:
 ODBC – “legacy” .asp scripting
 OLE DB – .aspx connectivity

Whichever is used…
 essential to get connectivity working correctly
» RAD tools very helpful…
 server-script can then use SQL commands to link to
and communicate smoothly with database tables
» again… RAD tool can save a lot of time…
Thanks for listening…
