Title: FT2283 Web Development
1FT228/3 Web Development
Active Server Pages IIS Web server
2Introduction
- Purpose to provide some practical experience of
using IIS web server and basic ASP pages - Active Server Pages Developed by Microsoft
- Active Server Pages is a programming model (as
is CGI) - Similar to JSP, script is interspersed with HTML
- Pages must have a file extension of .asp
otherwise, server wont know to process as an ASP
page
3Web Servers
- Microsoft has two web servers that are usually
used to run ASP - IIS (Internet Information Server Windows NT/XP
Pro/2000 - PWS (Personal Web server) up to Windows 98
- IIS is free with Windows 2000/XP Pro, part of the
Windows NT 4 option pack. - PWS is a scaled down version of IIS for Personal
Computers. - ASP pages can be run on other servers, provided
the server has the ASP engine. Sun Microsystems
have produced a product called Chili!Soft ASP
which enables ASP to be used on other web servers
including, Apache, I-Planet, Zeus, Red Hat Secure
Server, etc, using various operating systems
including, Linux, Solaris, HP-UX, AIX, etc.
4Set up a web site in IIS
- Open administrator tools in Control panel and
open the Internet Server Manager - Shows directory structure for IIS
- Default web site is the HTTP site. Expand the
default web site (shown overleaf) and create a
virtual directory in the Webpub directory - this
will hold the documents for your web site. (A
virtual directory is just an alias for a real
directory that exists). This virtual directory
will become part of the web address to access any
documents contained in it - e.g. http//localhost/Webpub/examples/blahblah.ht
ml
5(No Transcript)
6Set the access permissions
7Set up a web site in IIS
- Access permission security level choices for
the virtual directory - Read users can read and download files in the
directory Run Scripts allows scripts in the
directory to be run - Execute allows applications in the directory
(e.g. CGI )to be run - Write alows a Web page to accept user input
(e.g. credit card input - Browse allows users to navigate from one web
doc to another via hyperlinks
8Loading a document from IIS
- To load a HTML doc using IISFirst, ensure HTML
doc has been placed in the virtual
directoryThen type the web address for your
html doc into the browser. This will bee.g
http//localhost/webpub/alias/index.html - To load ASP documents do exactly as above, and
remember to access using .aspe.g
http//localhost/webpub/alias/somepage. asp
What ever you called the directory
9ASP
- When a browser requests an ASP file, IIS passes
the request to the ASP engine (ASP.dll). 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 - ASP pages are usually written using VBScript, but
can use other languages e.g. Microsofts Jscript - VBScript is the default language (VBScript is a
scaled down version of Visual Basic) - Scripting code CAN be made to run on the client
OR the server. e.g. can have an ASP page that
contains Javascript validation to run on client,
and VBScript for running on server (e.g. database
access)
10Uses of ASP
- Can be used similar to JSP for
- 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 - Provides security since your ASP code can not be
viewed from the browser - Since ASP files are returned as plain HTML, they
can be viewed in any browser
11Differences between VBScript and Visual Basic
- VBScript explicitly supports one data type only ,
the Variant - VBScript is an interpreted language
- VBSCript cannot directly use the Windows API
- There a a few syntactical different in the use of
some internal functions
12Readability of ASP pages
- Always always always ensure that code is
- INDENTED COMMENTED ID BLOCK
- Indented - to reflect level of the code
- ajsdlkfjads etc
- 2) Well commented. Comments in ASP appear as
the next subroutine will appear as followed
by a function which will calculate.. - Comments in HTML appear as
- HTML comments will be visible by view source in
browser, ASP comments wont.
13Readability of ASP pages
3) Titled At the top of each ASP page, should
have an ID block explaining who write the script,
date, script name, description and any revisions.
Can use either ASP or HTML comments (depending
on whether clients should be able to see the ID
block)
' Script name conversion.asp
' Author Jimmy Saville
Date July 7th 2003
Desciption whatever it does..
Revisions
August 8th 2003 added subroutine
'
etc
14ASP Syntax
- ASP files for web output usually contain HTML
tags. - Any scripts intended for execution by the server
must be between to distinguish them
from HTML - The ASP engine looks specifically for code
between - - this code will then be parsed by
the ASP engine. The remainder will be ignored
15ASP Scripting languages
- The default language for code is VBScript,
although other languages can be used e.g.
JavaScript, Jscript. - To set the language , use a language
specification at the first line of the page using
the _at_Language declarer -
- etc etc
- You dont have to set the language for VBSCript
as its the default but its good practice to
include it. - All examples here are in VBScript
16ASP- simple example
Wayne"response.write("My name is "
name)
- Using View Source at the browser will show HTML
only. - Dim used to create a variable name
- Write methods of Response object used to output
- Option Explicit enforces all variables to be
declared. Good practice
17ASP Declaring variables
- To declare a variable use Dim e.g Dim Actors
- Variables are of type variant (You dont have to
explicitly state string, integer etc.) - To declare an array add the array size on. e.g.
Dim Actors(3) - First element of the array has an index 0 e.g.
Actors(0) Tom - Function Ubound determines the upper index of the
arraye.g. Ubount(Actors) has a value of 4
18ASP Declaring variables - example
declare a few variables. Dim SomeText Dim
SomeNum 'Next we will assign a value to
these. SomeText "ASP is great!" SomeNum
1 'Note that SomeText is a string and SomeNum
is numeric. 'Next we will display these to the
user. Response.Write(SomeText) Response.Write
(SomeNum) 'You may also add (append) HTML code
to these. Response.Write ("Right now you are
thinking that " SomeText)
19ASP- Array example
. A list of the best actors
in the film
Actors(0) Tom Cruise Actors(1) Cillian
Murphy Action(2) Julia Roberts For I
0 to Ubound(Actors) OutStr OutStr
Actors(I)
Next
Response.Write(OutStr) etc
Do not have to include the Counter variable as
in VB.
20ASP Object Model
- ASP has seven built-in objects. Each of these
objects has a set of properties , methods and
collections that can be used to enhance ASP
pages - Request (Has a form collection to hold data
entered into a form) - Response (Has a write method to output to web
page) - Session
- Server
- Application
- ObjectContext
- ASPError(new)Detailed info at
http//www.asp101.com/resources/aspobject.asp
Data structures where number of elements is
variable (unlike arrays)
21ASP Object Model - Request
- Request - supplies information regarding the
request the user sends to the Web application - Request objects includes the following
collections - Form (values from the form elements sent by the
browser).Any elements in a HTML
are available to to ASP using Request.Form
(elementname) IF the post request method has
been used - QueryString values of the variables in a HTTP
query string, which is data sent to the server in
the URL I.e. www.blahblah.com?id2347name
jim QueryString is populated if the get
method is used -
22ASP Object Model Request HTML Form that
collects 3 pieces of info
.. header etc blue size 4 face arial "post" Action "processForm.asp" Your name
Your favourite colour txtColour
Your favourite film type text name txtFilm
type "submit" value "Click to submit
information" etc
23ASP Object Model Request output form content
onto a web page
4 The data entered into the form was
Name
Favourite colour tColour")
Favourite Film
etc
The Form collection of the Request object holds
all the request parameters
Note can use a short cut to output onto the web
page from a script. Instead of Response.write
can just use . Both ways shown here.
24ASP Subroutines and functions
- Use subroutines and functions in ASP pages in
order to economise on code.. I.e to enable
modules of code to be used and reused - Subroutines define a series of steps that
accomplishes some task, but does not usually
return a value - Functions accomplish a series of steps And
usually return a single value
25ASP Subroutines - example
response.write(num1num2) end sub The product of the two numbers entered
is request.form("firstNum") y
request.form("secondNum") Result calculate(x,y) etc
Subroutine always starts with Sub, ends with End
Sub
use Call
Arguments passed to subroutine (num1, num2)
26ASP Function example
etc dim tax taxprice.09 retailPrice
pricetax end Function etc..
etc price")) Response.write(The retail price
includig tax " y) etc
Function always startswith Function and ends
with End function Make sure that output is
explicitly named in the function
Retrieves a netprice and calculates the retail
price, using the function
27ASP- reusable code
- Very common in a web application to need to
include common code such as headers/footers/naviga
tion bars, subroutines etc across more than one
Web page. - ASP allows the use of a Server Side Include
directive called INCLUDE, which includes the
contents of another file into the current file.
Its the only SSI directive allowed in ASP (e.g.
echo, exec etc are not allowed) - Must surround the include SSI directive as a
HTML comment - Syntax
28ASP- reusable code - example
- Will include the contents of header.html into the
ASP page. It assumes header.html is in
subdirectory include, relative to to the current
directory. Note good practice to place all
include code into a single directory.. called
include
- Will include the contents of header.html into the
ASP page. It assumes header.html is the files
virtual path relative to the server root
directory. Its not concernted with current
directory.
29Comparing ASP versus JSP
- Similarities
- Both are scripting based technologies
- Both enable dynamic web pages
- Both help to separate the page design from the
programming logic - Both provide an alternative to CGI Scripts,
enabling easier and fast page development and
deployment - Compilation ASP was originally interpreted but
ASP.netuses compiled code, similar to JSP
30Using ASP versus JSP ?
- For a development project, how to choose whether
ASP versus JSP may be used? (assuming PHP and
others have been excluded!) - What technology is used already? ASP is usually
used with Microsofts IIS, which requires Windows
operating system -? tied into Microsoft
technology. Whereas JSP is platform independent
-? check whether the company is tied into any
particular vendor products already that will
guide decision - ASP JSP
- Web Server Microsoft IIS Any web
server, include apache, Netscape IIS - Platforms Microsoft Windows Most popular platforms
31Using ASP versus JSP ?
- Development skills - JSP support Javascript,
Java code and tags (custom and JSLT). ASP
supports both Vbscript and JavaScript. Need to
check which skills are already available in the
development team - Simplicity? ASP was traditionally regarded as
simpler to develop (VBScript) than JSP (using
Java code). However, the growth in use of
re-usable tag based actions for JSP is changing
this. If the company is open to using JSP tags,
both are relatively simple. - Re-usability across platform JSP will be
portable across platforms, ASP generally is not.
32Using ASP versus JSP ?
- Debugging/error resolution In JSP, the code is
converted into Java servlets in the background
any runtime errors refer to the servlet code
which can make it difficult to find the error.
ASP is not translated so any line references
are within the ASP page itself. - Code re-use - Both allow common code to be taken
out and re-used. JSP, with its use of custom and
JSLT tags, is probably superior on this. Use of
tags also enables easy global changes without
individual page change. - Performance JSP traditionally considered faster
as code is precompiled into servlets. However,
now that ASP is part of ASP.Net which is also
compiled ? comparable on performance.
33Using ASP versus JSP ?
- Open source JSP (and other java based
technologies from Sun) are developed with input
from the Java community. ASP is proprietary.
Cost/quality/vendor support implications.