1 / 87

IT in Education e-Leadership & Management Series

IT in Education e-Leadership & Management Series. Using Active Server Page (ASP) to create Simple Web-database Application. Speaker : PAU CHUNG WAI (Half-seconded Teacher). IT Management FWG’s Blog. http://edblog.hkedcity.net/itman. Reference Site. http://www.w3schools.com.

ilori
Download Presentation

IT in Education e-Leadership & Management Series

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. IT in Education e-Leadership & Management Series Using Active Server Page (ASP) to create Simple Web-database Application Speaker:PAU CHUNG WAI (Half-seconded Teacher)

  2. IT Management FWG’s Blog http://edblog.hkedcity.net/itman

  3. Reference Site • http://www.w3schools.com

  4. Part 1: Introduction

  5. Introduction to Dynamic Web Page • Dynamic means content on a web page can change in response to different context or conditions. • More interactive than static web page • Two ways: • Client-side Scripting (e.g. JavaScript, VBScript) • Server-side Scripting (e.g. PHP, Perl, ASP, JSP)

  6. What is ASP? • ASP stands for Active Server Pages • ASP is a program that runs inside IIS • IIS stands for Internet Information Services • IIS comes as a free component with Win XP and Vista

  7. How does ASP differ from HTML? • When a browser requests an HTML file, the server returns the file. • When a browser requests an ASP file, IIS passes the request to the ASP engine. 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.

  8. Web Server Request ASP Engine Response Client displayed in browser How does ASP differ from HTML?

  9. Advantages of using ASP? • Dynamically edit, change or add any content of a Web page • Access any data or databases and return the results to a browser • Provide security since your ASP code cannot be viewed from the browser

  10. Part 2: How to setup a Web Server?

  11. How to install IIS in Win XP? • To run ASP, IIS must be installed. • Follow these steps to install IIS on Windows XP: • On the Start menu, click Settings and select Control Panel. • Double-click Add or Remove Programs. • Click Add/Remove Windows Components. • Click Internet Information Services (IIS). • Click Details. • Select the check box for World Wide Web Service, and click OK. • In Windows Component selection, click Next to install IIS. • After you have installed IIS, make sure you install all patches for bugs and security problems.

  12. After Installation, you can find the IIS program icon in System Tools (系統管理工具):

  13. Right-click and then select “Properties (內容)”

  14. Primary Document Folder (Can be changed)

  15. Test your Web • Follow these steps after you have installed IIS: • Look for a new folder called Inetpub on your hard drive. • Open the Inetpub folder, and find a folder named wwwroot. • Create a new folder, “ASP", under wwwroot. • Copy all the sample files to this folder • Make sure your Web server is running. • Open your browser and type“http://localhost/ASP/testing.asp"to view your first web page.

  16. How to install IIS in Windows Vista? • On the Start menu, click Settings and select Control Panel. • Select Turn Windows Features On or Off from Programs and Features. • Select Internet Information Services. Expand the tree nodes of IIS, check the options that you want to turn on. (You must turnon ASP feature) • Then click OK to install IIS.

  17. How to install IIS in Windows Vista?

  18. TRUE How to install IIS in Windows Vista?

  19. How to install IIS in Win Server 2003? • When you start the Windows Server 2003, you should see the Manage Your Server wizard • If the wizard is not displayed, go to Administrative Tools, and select Manage Your Server • In the wizard, click Add or Remove a Role, click Next • Select Custom Configuration, click Next • Select Application Server role, click Next • Select Enable ASP.NET, click Next • Now, the wizard may ask for the Server 2003 CD. Insert the CD and let it run until it is finished, then click the Finish button • The wizard should now show the Application Server role installed

  20. How to install IIS in Win Server 2003? • Click on Manage This Application Server to bring up the Application Server Management Console (MMC) • Expand the Internet Information Services (IIS) Manager, then expand your server, and then the Web Sites folder • You should see the Default Web Site, and it should not say (Stopped) • IIS is running! • In the Internet Information Services (IIS) Manager click on the Web Service Extensions folder • Here you will see that Active Server Pages are Prohibited (this is the default configuration of IIS 6) • Highlight Active Server Pages and click the Allow button • ASP is now active!

  21. Part 3: Basic ASP Syntax

  22. Basic Syntax • ASP file normally contains HTML tags • Also contains server scripts, surrounded by the delimiter <% and %> • Server scripts are executed on the server • Results are plain HTML codes • Source codes not viewed by the web browser

  23. Example 1A example1a.asp <html> <body> <% response.write(“Hello World!”) %> </body> </html>

  24. Example 1B example1b.asp <html> <body> <% =“hello World!” %> </body> </html>

  25. Example 2A example2a.asp <html> <body> <% response.write(“The time now is ” & now()) %> </body> </html>

  26. Example 2B example2b.asp <html> <body> <% response.write(formatdatetime(now(),1) & "<br>") response.write(formatdatetime(now(),2) & "<br>") response.write(formatdatetime(now(),3) & "<br>") response.write(formatdatetime(now(),4) & "<br>") %> </body> </html>

  27. Variable • A variable is used to store information. • If the variable is declared outside a procedure it can be changed by any script in the ASP file. • If the variable is declared inside a procedure, it is created and destroyed every time the procedure is executed.

  28. Example 3 example3.asp <% X = “Hello World!” Sub Display() Dim X X = “Welcome!” Response.write(X) End Sub %> <html> <body> <% call display() %> <br> <% =X %> </body> </html>

  29. Procedure • You can call both a JavaScript procedure and a VBScript procedure in an ASP file

  30. Example 4 – Calling a VBScript Procedure example4.asp <html> <head> <% sub vbproc(num1,num2) response.write num1*num2 end sub %> </head> <body> <p> The result of 3 * 4 is <%call vbproc(3,4)%>. </p> </body> </html>

  31. Example 5 – Calling a JavaScript Procedure example5.asp <%@ language=“JavaScript”%> <html> <head> <% function jsproc(num1,num2) { Response.Write(num1*num2) } %> </head> <body> <p> The result of 3 * 4 is <%jsproc(3,4)%>. </p> </body> </html>

  32. Session Object • The Session object is used to store information about, or change settings for a user session. • Variables stored in the Session object hold information about one single user, and are available to all pages in one application.

  33. Example 6 example6.asp <html> <head> <% Session(“Username”) = “Raymond” %> </head> <body> <p> My name is <%=session(“Username”)%>. </p> </body> </html> Keep the browser open, browse another ASP file called “example7.asp”.

  34. Example 7 example7.asp <html> <head> </head> <body> <p> My name is <%=session(“Username”)%>. </p> </body> </html> Now, close all the browsers, Open “example7.asp” again. What do you see?

  35. Session Object • A session ends if a user has not requested or refreshed a page for a specified period. (By default, this is 20 minutes) • You can set the timeout property: <% Session.Timeout=5 %>

  36. Session Object • To end a session immediately, you may use the Abandon method: <% Session.Abandon %> Can you name one application of the Session object?

  37. Application Object • The Application object is used to store and access variables from any page, just like the Session object. • The difference is that ALL users share one Application object, while with Sessions there is one Session object for EACH user. • The Application object in ASP is used to tie these files together.

  38. Application Object • You can create Application variables in “Global.asa” <script language="vbscript" runat="server"> Sub Application_OnStart application("vartime")="" application("users")=1 End Sub </script>

  39. What is Global.asa? • The “Global.asa” file is an optional file that can contain declarations of objects, variables, and methods. • It can be accessed by every page in an ASP application. • The “Global.asa” file must be stored in the root directory of the ASP application, and each application can only have one “Global.asa” file.

  40. This “Global.asa” file counts the number of current visitors Example 8 Global.asa <script language="vbscript" runat="server"> Sub Application_OnStart Application("visitors")=0 End Sub Sub Session_OnStart Application.Lock Application("visitors")=Application("visitors")+1 Application.UnLock End Sub Sub Session_OnEnd Application.Lock Application("visitors")=Application("visitors")-1 Application.UnLock End Sub </script> Save this file in the root directory (i.e. c:\inetpub\wwwroot\)

  41. To display the number of current visitors in an ASP file: Example 8 example8.asp <html> <head> </head> <body> <p> There are <%response.write(Application("visitors"))%> online now! </p> </body> </html>

  42. The #include Directive • You can insert the content of one ASP file into another ASP file. • The #include directive is used to create functions, headers, footers, or elements that will be reused on multiple pages.

  43. Example 9 example9.asp <html> <body> <h3>Words of Wisdom:</h3> <p><!--#include file="wisdom.inc"--></p> <h3>The time is:</h3> <p><!--#include file="time.inc"--></p> </body> </html>

  44. Example 9 Here is the content of "wisdom.inc" file: "One should never increase, beyond what is necessary, the number of entities required to explain anything." Here is the content of “time.inc" file: <% Response.Write(Time) %>

  45. Part 4: Web forms handling

  46. User Input • Form is usually used to collect information from user. For example: <html><body><form action=“display.asp" method="get">Your name: <input type="text" name="fname" size="20"><input type="submit" value="Submit"></form></body></html> • Get or Post method could be used. • Action defines the ASP file that accepts the user inputs.

  47. Request Object • The Request object may be used to retrieve user information from forms. For example: <html><body><form action="example10.asp" method="get">Your name: <input type="text" name="fname" size="20"><input type="submit" value="Submit"></form><%fname=Request("fname")If fname<>"" Then      Response.Write("Hello " & fname & "!")End If%></body></html> example10.asp Let’s try another method - “Post”

  48. Classwork 1 • Create the following ASP file that accepts name and sex as input, then output the text as indicated.

More Related