1 / 52

ASP (Active Server Page)

ASP (Active Server Page). طراحي صفحات وب پويا (برنامه نويسي سمت سرور). Morteza Sargolzaie Javan http://www.msjavan.tk IT Scientific Society. Static Web Pages. Page content doesn ’ t change. Same every time it is delivered by the web server Pages we have created so far.

Download Presentation

ASP (Active Server Page)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ASP (Active Server Page) طراحي صفحات وب پويا (برنامه نويسي سمت سرور) Morteza Sargolzaie Javan http://www.msjavan.tk IT Scientific Society

  2. Static Web Pages • Page content doesn’t change. • Same every time it is delivered by the web server • Pages we have created so far IT Scientific Society - December 2006

  3. Static Web Page Delivery Web Server 1 3 Web server locates .htm file Author writes HTML 4 HTML stream returned to browser 5 2 Browser processes page Client requests page IT Scientific Society - December 2006 Client

  4. Dynamic Web Pages • Created on the fly based on user actions or current conditions. • Allows the page to be customized to the user and the situation. IT Scientific Society - December 2006

  5. Server-side vs. Client-side Processing • Computer processing can happen in two locations • Server: • Accepts request, finds page, sends it • Client: • Gets HTML (or more?) from net, processes it, displays it • Advanced things can happen on one or both sides IT Scientific Society - December 2006

  6. Server-side Dynamic Page Delivery Web Server 3 Web server locates instructions file 1 4 Author writes instructions Web server processes instructions to create HTML 5 HTML stream returned to browser 6 2 Browser processes page Client requests page IT Scientific Society - December 2006 Client

  7. Client-side Web Page Delivery Web Server 3 Web server locates instructions file 1 4 HTML and script are returned to browser Author writes instructions 5 Web browser processes script to create HTML 2 Client requests page 6 Browser displays HTML Client IT Scientific Society - December 2006

  8. Many Technology Choices • Client-Side Technologies: • Scripting languages: JavaScript, VBScript • Java applets • XML • Server-Side Alternatives: • CGI • Active Server Pages (ASP) • PHP • Java Server Pages (JSP) • ColdFusion IT Scientific Society - December 2006

  9. Server-side Processed by server Does not rely on browser support Provide browser with data that does not reside on client Script code not visible in page source Can Manage sessions (shopping baskets, etc.) Database processing Client-side Processed by browser Does not depend on web server requirements Does not need to interact with server to create content processed by browser Script code is viewable in page source Server-side scripts or Client-side scripts? IT Scientific Society - December 2006

  10. Server- and Client-side Scripting Web Server 3 Web server locates page file 1 4 Author writes page code Web server asks script engines to process scripts & generate HTML 5 HTML stream passed back to server 6 Browser processes client side scripts 2 7 Client requests page Browser processes HTML & displays page Client IT Scientific Society - December 2006

  11. ASP – Middleware for Windows platform • ASP stands for Active Server Pages • VBScript is the default scripting language for ASP • If you are looking for some special software to write an ASP page, Microsoft Visual InterDev is the best tool for you. IT Scientific Society - December 2006

  12. ASP – Middleware for Windows platform • Active Server Page can include both client side and server side scripts. • In an ASP page VBScript is usually used as the server side and Java Script as the client side scripting language IT Scientific Society - December 2006

  13. What is an ASP file? • An ASP file is just the same as an HTML file • An ASP file can contain text, HTML, XML, and scripts • Scripts in an ASP file are executed on the server • An ASP file has the file extension *.asp IT Scientific Society - December 2006

  14. What is an ASP file? <HTML> <HEAD> <TITLE>Hello World</TITLE> </HEAD><BODY> <% ' This will print to the browser the ' words Hello, ASP World. response.write "Hello, ASP World!" %> </BODY></HTML> IT Scientific Society - December 2006

  15. What can be done with ASP • 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 IT Scientific Society - December 2006

  16. Client/Server Interaction for ASP Files Server Client Server locates the ASP file on the hard drive and parses it, removing all ASP script and replacing it with HTML text Client requests ASP File Server returns HTML text to client IT Scientific Society - December 2006 Taken from Mitchell & Atkinson (2000)

  17. Client/Server Interaction for ASP Files <HTML> <HEAD> <TITLE>Hello World</TITLE> </HEAD><BODY> <% ' This will print to the browser the ' words Hello, ASP World. response.write "Hello, ASP World!" %> </BODY></HTML> File On Server <HTML> <HEAD> <TITLE>Hello World</TITLE> </HEAD><BODY> Hello, ASP World! </BODY></HTML> Result on Client IT Scientific Society - December 2006

  18. ASP compatibility • ASP is an engine/program built into Internet Information Server (IIS) / Personal Web Server (PWS) • PWS is a smaller - but fully functional - version of IIS • To run IIS you must have Windows NT 4.0 or later • To run PWS you must have Windows 95 or later IT Scientific Society - December 2006

  19. Installing IIS IT Scientific Society - December 2006

  20. Running IIS IT Scientific Society - December 2006

  21. IIS Environment IT Scientific Society - December 2006

  22. IIS Default Folder IT Scientific Society - December 2006

  23. Opening an ASP File http://localhost/page.asp http://127.0.0.1/page.asp http://[Computer-name]/page.asp IT Scientific Society - December 2006

  24. What Does ASP Look Like in Action? IT Scientific Society - December 2006

  25. What Does ASP Look Like in Action? • What HTML “looks like” <p>Analytical Ultracentrifugation Workshop (May 21-23, 2001) and Symposium (May 24, 2001) at the National Analytical Ultracentrifugation Facility, Storrs, Conn. For additional information</p> <ul> <li><a href="http://www.ucc.uconn.edu/~wwwbiotc/99wkshp.html" target="_blank"> National Analytical Ultracentrifugation Facility</a></li> <li><a href="naufworkshop.asp">Analytical Ultracentrifugation Workshop and Symposium Description and Registration (PDF Format)</a></li> </ul> IT Scientific Society - December 2006

  26. What Does ASP Look Like in Action? • What the “real code” looks like* <% If Today < CDate("5/25/01") Then %> <p>Analytical Ultracentrifugation Workshop (May 21-23, 2001) and Symposium (May 24, 2001) at the National Analytical Ultracentrifugation Facility, Storrs, Conn. For additional information</p> <ul><li><a href="http://www.ucc.uconn.edu/~wwwbiotc/99wkshp.html" target="_blank">National Analytical Ultracentrifugation Facility</a></li> <li><a href="naufworkshop.asp">Analytical Ultracentrifugation Workshop and Symposium Description and Registration (PDF Format)</a></li> </ul> <% End If %> IT Scientific Society - December 2006

  27. ASP Object Model • ASP itself is not Object-Oriented. ASP can use objects but cannot define new objects • Composed of • 5 objects • 5 components IT Scientific Society - December 2006

  28. ASP Objects • Request • Response • Server • Application • Session IT Scientific Society - December 2006

  29. ASP Components • Scripting Objects Component • ADO (ActiveX Data Objects) Component • Ad Rotator Component • Browser Capabilities Component • Content Linking Component IT Scientific Society - December 2006

  30. Request • Can get input from query string or form • Can get cookie information • Can also get total bytes, certificate, server variables • Example <% Request.QueryString (“fname”) %> IT Scientific Society - December 2006

  31. Response • Can send output to user through web page • Can set cookie values • Can set character set, expiration • Can clear, write, flush output • Can redirect • Example <% Response.Write “message” %> IT Scientific Society - December 2006

  32. Session • Store user information during request and response and request and response…. • Want to identify, maintain user information or state in stateless HTTP protocol • Client has an id number and expiration time from last request or expires • Client can terminate or abandon causing Session object to be destroyed as well IT Scientific Society - December 2006

  33. Application • Information about entire website • Global variables • Example is a counter • Lock and UnLock to access to update IT Scientific Society - December 2006

  34. Server • Server related utility functions • Script time out for running say a DB query • Create an object like DB object • Can enable URL encoding • Example: Request.ServerVariable(REMOTE_ADDR) IT Scientific Society - December 2006

  35. VBscript • <% … %> open and close script area • <% Response.Write (“message”) %> • <% = “message” %> • <% = sStr1 %> • & is concatenate operator • <% Request.QueryString(“fname”) %> • <% Request (fname) %> • Server.CreateObject(“ADODB.connection”) • Include statement for reuse of say login, password IT Scientific Society - December 2006

  36. Logic • If … then …. Else … end if • Not case sensitive • For statement For I = 1 to 8 statements Next • While statement Wend • Case statement IT Scientific Society - December 2006

  37. Functions • Type casting like CStr(expression) • Checking type, Date, • Searching (strings) • Math abs(number) • Also, user defined function and subroutines. Function can return a value, subroutines cannot, and example: Function add(a,b) add=a+b End Function IT Scientific Society - December 2006

  38. Operators • Concatenation operator is & (watch use of ‘ and “ to build string with variables) • + - * < > or and mod etc. • = also = to print out IT Scientific Society - December 2006

  39. ASP Syntax • VBScript: <html> <body> <% response.write("Hello World!") %> </body> </html> • JavaScript <%@ language="javascript" %> <html> <body> <% Response.Write("Hello World!") %> </body> </html> IT Scientific Society - December 2006

  40. Variables • <html><body><%dim namename=“Javan"response.write("My name is: " & name)%></body></html> IT Scientific Society - December 2006

  41. Arrays • <html><body><%Dim famname(6),ifamname(1) = "Jan Egil"famname(2) = "Tove"famname(3) = "Hege"famname(4) = "Stale"famname(5) = "Kai Jim"famname(6) = "Borge"For i = 1 to 6 response.write(famname(i) & "<br />")Next%></body></html> IT Scientific Society - December 2006

  42. Loops • <html><body><%dim i for i=1 to 6 response.write("<h" & i & "> Header " & i & "</h" & i & ">")next%></body></html> IT Scientific Society - December 2006

  43. Example (VB) • <html><body><%dim hh=hour(now())response.write("<p>" & now() &”</p>”) • If h<12 then response.write("Good Morning!")else response.write("Good day!")end if%></body></html> IT Scientific Society - December 2006

  44. Example (JavaScipt) • <%@ language="javascript" %><html><body><%var d=new Date()var h=d.getHours()Response.Write("<p>“ + d + “</p>”)if (h<12) { Response.Write("Good Morning!") }else { Response.Write("Good day!") }%></body></html> IT Scientific Society - December 2006

  45. Procedures (VB) <html> <head> <% sub vbproc(num1,num2) response.write(num1*num2) end sub %> </head> <body> <p>Result: <%call vbproc(3,4)%></p> </body> </html> IT Scientific Society - December 2006

  46. Procedures (JavaScript) <%@ language="javascript" %> <html> <head> <% function jsproc(num1,num2) { Response.Write(num1*num2) } %> </head> <body> <p>Result: <%jsproc(3,4)%></p> </body> </html> IT Scientific Society - December 2006

  47. Forms <form method="get" action="simpleform.asp"> First Name: <input type="text" name="fname"> <br /> Last Name: <input type="text" name="lname"> <br /><br /> <input type="submit" value="Submit"> </form> IT Scientific Society - December 2006

  48. Sending Information over get method /simpleform.asp?fname=Morteza&lname=Javan IT Scientific Society - December 2006

  49. Process Information <body> Welcome <% response.write(request.querystring("fname")) response.write(" " & request.querystring("lname")) %> </body> IT Scientific Society - December 2006

  50. Cookies • Create a Cookie: <% Response.Cookies("firstname")="Alex" %> • Retrievea Cookie value: <% fname=Request.Cookies("firstname") response.write("Firstname=" & fname) %> IT Scientific Society - December 2006

More Related