Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
1
Need to Study
• Active Server Pages (ASP)
• Active Server Pages (ASP): Concept of ASP, features of ASP,
• Variables: Explicit and Implicit
• Declaration;
• Functions:
• String Manipulation Functions: Ucase O, Lcase O, Len O, Left O,
• Right O, Mid O, Ltrim O, InStr0
• Time & Date Functions: Date O, DayO, Hour 0, Left O, Len O, Minute
• 0, Month O, Monthname O, Now O;
• Arrays: Declaration and use of 1 dimensional and 2 dimensional
• arrays;
• Procedures and Functions, Passing parameters/ arguments;
• Connecting with Databases: Creation of DSN, using OLEDB.
2
Static HTML and
the HTTP Protocol
HTTP designed as a doc fetching protocol:
3
Dynamic HTML
4
Dynamic Pages
6
Server Side Scripting
• Useful to interact with data stored on the server
(databases, images, etc.)
• And when centralized processing is needed
• Sever needs to support the scripting language
• Most popular:
CGI Perl (Unix)
ASP VB Script or JScript (Windows)
7
Server Side Scripting (cont’d)
• Embedded scripts in HTML page
HTML code
<% (marks the beginning of ASP script)
………..……….
ASP script code
………………....
%> (marks the end of ASP script)
More HTML code
<% more ASP %>
Etc.
8
Dynamic HTML with ASP
1. Client clicks on URL with .asp file
2. Web server notices file extension .asp
Note: Only Windows NT IIS web server supports ASP
3. Server then processes .asp file
4. Server creates a new HTML file
5. Contains all original HTML stuff
6. Plus processing results from ASP code
7. Dynamically formatted as HTML
8. Server sends the new HTML file to client
9
10
How ASP works
11
Web Applications
http://sundown.wou.edu:81/en/mail.html?lang=en&laurel=on&cal=1
17
Dynamic HTML with ASP
ASP code on server HTML code sent to client
<H3>Welcome to my page</H3> Same <H3>Welcome to my page</H3>
<H2>Here is my product list</H2> <H2>Here is my product list</H2>
<P>
<% ‘Start ASP code <B>Product Price</B>
Open a database connection Dynamically <HR>
SQL queries to database generated <P>Hammer ……... $8.50
Copy results to a record set by ASP <P>Pliers ……….… $7.79
Display records one at a time <P>Screwdriver ..… $4.50
<P>Power Drill ….. $49.99
Close database connection <P>Chainsaw …… $95.95
%> ‘End ASP code <P>Wrench ……….. $6.50
<P>Thank you very much for <P>Thank you very much for
inquiring about our products Same inquiring about our products
18
ASP, SQL, Databases, and HTML
Web Server
MS IIS Web Server
SQL Query
Databases ASP HTML
Query HTML
Results Request
Dynamic
HTML ASP HTML doc
Produced Request Fetched
On-the-Fly
Client Browser
Internet Explorer
Netscape Navigator
19
Common Uses of ASP
20
Example--ASP on Server (Query)
<% Set conn = Server.CreateObject("ADODB.Connection")
conn.open "orders "
Set rs_customers = Conn.Execute("SELECT clientID, clientName,_
shipAddress, telephone FROM clients") %>
</TABLE></BODY></HTML>
21
Example--Response to Browser
<IMG SRC="music22.gif"><B>Alberto's Music Instruments, Inc.<p>
<TABLE BORDER="0"><B>Customer List</B>
<TR><TH>ClientID</TH> <TH>Client Name</TH>
<TH>Shipping Address</TH> <TH>Telephone</TH> </TR>
<TR><TD>josee</TD>
<TD>Alberto Espinosa</TD>
<TD>Schenley Park, GSIA Building, #20</TD>
<TD>412-268-3681<BR></TD> </TR>
<TR><TD>sandy</TD>
<TD>Sandra Slaughter</TD>
<TD>5000 Forbes Avenue, Pittsburgh PA 15213</TD>
<TD>412-268-3681<BR></TD> </TR>
etc.
</TABLE></BODY></HTML>
22
Example--ASP on Server (Data Input)
<B>Customer Registration</FONT></B><P>
<FORM ACTION=
"http://softrade-11.gsia.cmu.edu/data/customerSubmit.asp"
METHOD="POST" ENCTYPE="x-www-form-urlencoded">
<TABLE>
<TR><TD>Please enter a customer ID (4 to 16 characters)</TD>
<TD><INPUT TYPE="text" SIZE="35" NAME="CustomerID" VALUE=" ">
</TD></TR>
<TR><TD>Please enter your name</TD>
<TD><INPUT TYPE="text" SIZE="35" NAME="CustName" VALUE=" ">
</TD></TR>
etc.
</TABLE>
</TABLE></FORM></BODY></HTML>
23
Example--ASP on Server (Data Input)
<!-- customerSubmit.asp -->
<HTML><BODY><CENTER>
customerId = Request.Form("customerId")
custName = Request.Form("custName") …. etc.
Conn.Close %>
</CENTER></BODY></HTML>
24
ASP Features
• Cross-platform & container support.
• High performance.
• Asynchronous via async/await
• Unified MVC & Web API frameworks.
• Multiple environments and development mode.
• Dependency Injection.
• WebSockets & SignalR.
• Cross-Site Request Forgery (CSRF) Protection
• Self hosted” Web Applications
• Action Filters
25
String- Len()
• <%
Dim strtest,varlength
strtext=”Howareyoudoing?”
varlength=Len(strtext)
response.write(varlength)
%>
• Result
is 15
26
• Asp – Right() and Left() functions
• Returns a given
number of characters from the beginning and end of a string.The syntax is :
• Right(string,NumberOfCharecteres)
Left(string,NumberOfCharecteres)
• Eg:
<%
Dim strtest,str1,str2
strtext=”Howareyoudoing?”
str1=Right(strtext,6)
str2=Left(strtext,3)
How 27
• Asp – InStr Function
• The syntax is:
•
Instr(string,StringToBeLocated)
• This returns the
position at which the StringToBeLocated was found.This returns
0 if StringToBeLocated is not found or if StringToBeLocated is
zero-length.This returns null if string or StringToBeLocated is
null.
• Eg:
<%
Dim strtest,intfound
strtext=”Howareyoudoing?”
intfound = instr(strtest,”you”)
if intfound>0 then
response.write(“String Found”)
28
Else
• Asp – mid() Function
• This function
returns the requested number of characters from a string.This works along the
same principle as Right() or Left() , but it takes an extra parameter.
• The syntax is:
Mid(String, CharToStartWith,
NumberOfCharectersToBeExtracted)
• Eg:
<%
Dim strtest,str1
strtext=”Howareyoudoing?”
str1 = mid(strtext,4,3)
response.write(str1)
%>
• Result
is : are
• if
NumberOfCharectersToBeExtracted is left out, Mid will return all of the characters
starting from CharToStartWith.
29
• Asp – Trim(),LTrim() , RTrim() Functions
• The function LTrim()
removes spaces from the left hand side of the string, RTrim() removes
spaces
from right hand side of a string and Trim() function combines the
two,removing
all the spaces from right and left end of the string.
•
30
• <% Response.Write(Date()) %>
Or
<%=Date%>
Out Put : 3/28/2019
31
formatdatetime function
• The Format Date Time function takes two arguments: a date and (optional) an integer from 0
through 4. The meanings of these numbers are as follows:
• 0 - This is the default setting. A short date DD/MM/YYYY will be used.
• 1 - A long date defined by the computer's regional settings.
• 2 - A short date defined by the regional settings.
• 3 - (time)A time using the time format defined by the regional settings.
• 4 - (time)A time using military time HH:MM (H = hour, M = Minute)
• Below is an example of all five used to format the Date function.
• ASP Code:
• <% Response.Write("0 = " & FormatDateTime(Date, 0))
Response.Write("<br />1 = " & FormatDateTime(Date, 1))
Response.Write("<br />2 = " & FormatDateTime(Date, 2))
Response.Write("<br />3 = " & FormatDateTime(Date, 3))
Response.Write("<br />4 = " & FormatDateTime(Date, 4)) %>
• Display:
• 0 = 3/28/2019
1 = Friday, October 21, 2005
2 = 3/28/2019
3 = 12:00:00 AM
4 = 00:00
32
ASP Array
<%
a=Array(5,10,15,20)
response.write(a(3))
%>
33
<% Dim myFixedArray(3)
myFixedArray(0) = "Albert Einstein“
myFixedArray(1) = "Mother Teresa"
myFixedArray(2) = "Bill Gates"
myFixedArray(3) = "Martin Luther King Jr." %>
34
Array Iteration
<%
a=Array(5,10,15,20)
for each x in a
response.write(x & "<br />")
next
%>
35
2D Array
• <%
Dim arrCars(2,4)
'arrCars(col,row)
arrCars(0,0) = "BMW"
arrCars(1,0) = "2004"
%>
36
Functions
37
Functions Return
• <%@ LANGUAGE="VBSCRIPT" %>
<%
function Square(num)
Square = num * num
end function
Response.Write(Square(5))
%> 38
Procedure
• <%@ LANGUAGE="VBSCRIPT" %>
<%
sub PrintProfit(Revenue, Overhead, COGS, Admin)
'Create a variable to store our profit
Dim Profit
39
Functions Vs Procedure
• The function must return a value but in
Stored Procedure it is optional. Even a
procedure can returnzero or n values.
Functions can have only input parameters
for it whereas Procedures can have input
or output parameters. Functions can be
called from Procedure whereas Procedures
cannot be called from a Function.
40
Abbrevations
• DSN- Data Source Name
• OLEDB-Object Linking and Embedding Data Base
• ODBC- Open Data Base Connectivity
• ADO- ActiveX Data Object
• ASP – Active Server Pages
• IIS – Internet Information Services
• HTML – Hyper Text Markup Language
41