250 likes | 650 Views
Today: Introduction to ASP- Part 1. Explain the client/server architecture Explain Web-based client/server applications Understand the essentials of Active Server Pages Write and edit simple ASP files. Client/Server Architectures. What is Client/Server Architecture?.
E N D
Today: Introduction to ASP- Part 1 • Explain the client/server architecture • Explain Web-based client/server applications • Understand the essentials of Active Server Pages • Write and edit simple ASP files.
Client/Server Architectures What is Client/Server Architecture? Client/Server Architecture is the structural design of a computer network. Components; - Clients, or client computers and their software - Servers, which include hardware and software
Client/Server Architectures A typical Client/Server Relationship • Users at the client computers send service requests to a server computer • - The server computer process the requests sends the results back to the • client computers.
Web-Based Client/Server Applications Flowchart of a Sample Web-based, three-tiered Client/Server architecture Web Server Data Server Web Browser Access-SQL Server- Oracle IIS- Apachi Internet Transaction server Database Internet Explorer - Netscape Application Servers
Active Server Pages • Active Server Pages (ASPs) are Web pages • ASP = server-side scripts + HTML • The appearance of an Active Server Page depends on who or what is viewing it. • If the Web browser that receives it, an Active Server Page looks just like a normal HTML page. • However, the file located in the server looks very different. In addition to text and HTML tags, you also see server-side scripts. • This is what the Active Server Page looks like to the Web server before it is processed and sent in response to a request.
How ASP Works? User brings up a Web site where the default page has the extension .asp. The browser requests the ASP file from the Web server The server-side scripts begins to run with ASP. ASP processes the requested file sequentially (top-down), executes any script command contained in the file, and produces an HTML Web page. The Web page is sent to the browser.
ASP vs HTML • ASP = HTML + some other stuff! • What is the difference? Basically we are taking the HTML and adding some elements... • ASP files end with the .asp extension, so the Web server knows what it is. • ASP files include server-side code that contain instructions for the server. • Browser can not display your code! • ASP files provide dynamic information
Active Server Pages Server-side scripts ~ HTML tags. <%...%> ~ <...> You can insert server-side scripts anywhere in your Web page--even inside HTML tags. <h1> <% = “Hello World” %> </h1> The server looks inside the ASP tags and runs the instructions, sends the results
Variables Every application uses variables, and ASP scripts are no exception! But there is no obligation in Visual Basic and VbScript No need to define the variables and variable types at the beginning of the program. But if you want you can... If you add the following line after the language info to the page; <% Option Explicit %> You must declare your variables. i.e. dim number1 dim number2
Variables Basic Variable Types: numeric, alpha-numeric, and logical. No need to know other variable types, because when you assign a value to a variable, Visual Basic understands your variable type! variable_1 = 15 variable_2 = “15” variable_3 = true If you want to learn type of any variable; <% variable_1 = 15 Response.write vartype(variable_1) ‘it writes 2 to the page %> List of Variant type variables of the VBScript vbNull 1 contains no data, vbInteger 2 integer type, vbLong 3 .....
VBScript Looping – flow controls Looping constructs provide the foundation for any application that must repetitively perform a task. Such as adding 1 to a variable, reading a text file, or processing an e-mail message. VBScript and Jscript provide several looping mechanism. For... Next, For each ... in ...Next, Do.. Loop While, Do...While...Loop, Do..Until...Loop, Do...Loop Until..., While ...Wend conditional operators Conditional operators, together with variables and looping constructs, for the fundamental building blocks of applications. Such as sending a page to the client browser that consists of the current time and date and a greeting If..Then, If...then...else, If...then...Elseif...then else, Select...Case, Switch..case
How to Create ASP Pages? • Open notpad • Create the necessary HTML codes. • Add ASP codes into their respective places. • Save your file with the extension .asp. • Design the followings in FrontPage:
How to Create ASP Pages ? • Switch to HTML tab.
How to Create ASP Pages? • Add ASP codes into their respective places.
Reponse.Write ( ) Response object is the part of ASP that handles responding to the request of a browser If you want to display information to Web page Write method of the response object will be used. <% Response.Write(“Hello World”) %> NOTE : equal sign (=) is a short-cut of response.write object <% = “Hello World” %>
How to Save ASP Pages? • Save your file with the extension .asp. Write asp extension with the file name. OR Select Active Server Pages option as file type. So, you do not need to write file extension.
Another example! (“for – next”) We want to write “hosgeldiniz” in 5 different font size!
html TunaTuna <B>Tuna</B> Tuna <font size = “2”>Tuna</font> response.write“<font size = “2”>Tuna</font>“ typeMismatch Handling HTML codes in ASP codes <% response.write “ “ & “ “ & i%> <% Response.write “<BR>” %>
response.write response.write“<font size = “2”>Tuna</font>“ Handling Error: 1st way: Do not use “ “ in HTML! But; <font face = lucida handwriting> face = lucida ? <% response.write<table width = 100%> %> ? 2nd way: use ‘ ‘ instead of “ “ Examples: Example 1:Adding 2 numbers <% num1 = 40 num2 = 30 response.write num1 + num2 %>
response.write Example 2:finding y <%a=1b=5c=2y= b*b - 4*a*cresponse.write y%> Example 3:finding the square of 2 numbers and the addition of their square <%num1 = 10num2 = 20sq1 = num1 * num1sq2 = num2 * num2sum = num1 + num2response.writesq2 &","& sq1 & "," & sum
response.write & if..then..else..end if Example 4:VAT included Price <%VAT = 18PRICE = 3000000VAT_INC = PRICE + (PRICE * VAT)/100Response.Write "VAT included price is"& " " & VAT_INC%> Example 5:positive or negative? <%num = 89IF num >0 THENresponse.write num &" "& "is a positive number.“ELSEresponse.write num &" "& "is a negative number.“END IF%>
response.write & if..then..else..end if Example 6: If a number less than 10, output it's square otherwise the number only.<% num = 9IF num > 10 THENsq = num * numresponse.write sqELSEresponse.write numEND IF%> Example 7: Subtract the smaller from the larger <%num1 = 3num2 = 5IF num1>num2 THENnum = num1 - num2ELSEnum = num2 - num1END IF Response.Write num%>
response.write & if..then..else..end if Example 8: SNG room 100$ others 150$> <% room_type = "DBL“num_of_night = 10IF room_type = "SNG" THENprice = 100 * num_of_night ELSEprice = 150 * num_of_nightEND IFResponse.Write "room price is " & price%> Example 9: PASS, FAIL <% final = 50IF final >= 50 THENResponse.Write "PASS“ELSEResponse.Write "FAIL“END IF%>