Title: Server-side programming - ASP
1Session 6
- Server-side programming - ASP
2What is ASP?
- An ASP page is an HTML page interspersed with
server-side - code.
- The .ASP extension instead of .HTM denotes
server-side code - to the hosting Web server.
- You can use any text editor to create or change
an ASP file
Sets the default for the page
lt_at_LANGUAGE "JavaScript"gt lt var varSurname
Request.form("surname") gt lthtmlgt ltbodygt lt sql
"Select from tblStock" gt THIS IS
HTML Surname ltvarSurnamegt
Gets data from form on previous page
The ASP is between lt and gt
Outputs the variables content
3Open Database Connectivity(ODBC)
These databases know how to interact with ODBC
- ODBC is an intermediary technology that allows
databases made by different manufacturers to
communicate with different interfaces e.g. ASP
pages. - The web server has ODBC drivers installed upon it
which interpret the dialogue into a common
language that each database understands.
Adapted from Resselman, 2000
4Browsers
- Display data primarily in HTML format.
- Accept user input from HTML form elements
- ASP pages are a mixture of hard-coded HTML (menu
bars, other static page content) and dynamically
generated HTML. - ASP (operating at the server-side) must therefore
send the data from the server to the client in
HTML format. All the calculations for doing this
are performed at the server side, using the
server's processor.
5Client
HTTP Request
Web Server
HTTP Response
Components
VBScript
IIS
ActiveX Data Objects (ADO)
JavaScript
ActiveX Scripting Engines
Database
ASP File
6Stages for ASP
- Client requests ASP page from server
- HTML and script code are separated.
- Script code is parsed, syntax checked and
compiled by Web server by appropriate scripting
engine - Code is executed by the appropriate scripting
engine - Script output and static HTML code are merged
- Final HTML is sent back to the user
7Anatomy of an .asp Page
lthtmlgt ltheadgt lt/headgt ltbodygt lt/bodygt lt/htmlgt
Note the code appears where the data will be
output on screen.
8Returning Records from a DB Using ASP
- Open a connection to the database, using the
connection object. - Create a query string variable containing the SQL
for the query. - Create a recordset object, then run the query on
it. - Loop through the records and format and display
each as HTML.
9lt_at_ LANGUAGE"JAVASCRIPT" gt lt myconn
CreateObject("ADODB.Connection") rs
CreateObject("ADODB.Recordset") myDB
"DriverMicrosoft Access Driver
(.mdb)DBQe\\webareas\\sr65\\sdg.mdb"
10sql "Select from tblStock order by
Stock_id" rsmyconn.Execute(sql) while (!
rs.eof) gt Item ltrs("Description")gtltbr
/gt lt rs.MoveNext rs.Close gt