370 likes | 521 Vues
CSC317 – INTERNET PROGRAMMING CSC318 – DYNAMIC WEB APPLICATION DEVELOPMENT. BY: SITI NURBAYA ISMAIL FACULTY of COMPUTER and MATHEMATICAL SCIENCES. Outline. Introduction to Server-Side Scripting. How does a server side page work? Introduction to IIS/PWS ASP Requirements What is ASP?
E N D
CSC317 – INTERNET PROGRAMMINGCSC318 – DYNAMIC WEB APPLICATION DEVELOPMENT BY: SITI NURBAYA ISMAIL FACULTY of COMPUTER and MATHEMATICAL SCIENCES
Outline Introduction to Server-Side Scripting • How does a server side page work? • Introduction to IIS/PWS • ASP Requirements • What is ASP? • How ASP file looks like? • Form Processing Using ASP • JavaScript vs VBScript • Other Server Scripting Language Page 2
Introduction to Server-Side Scripting How does a server side page work? • Basically, A Web requires two components: a Web server and a client • The client is usually a browser (I.E/Firefox/Chrome/etc) • Both the server & the client can communicate each other • Must use a defined protocol to communicate • The most common protocols are HTTP & FTP and also carried over an underlying network protocol called TCP/IP • The client sends an initialization (is a defined series of bytes) to start a session, when the server receives the initialization request, it acknowledges the transmission by returning another series of bytes to the client Page 3
Introduction to Server-Side Scripting How does a server side page work? • The conversation between client & server continues in this back-and forth manner • You can imagine the conversation being conducted as follows: Page 4
Introduction to Server-Side Scripting Introduction to IIS/PWS • You can choose either IIS/PWS as a web server to run your ASP file • If you choose IIS, you must have access to a Windows NT 4.0 server with IIS 4.0 or Windows 2000 Server with IIS 5.0 • Or you can install PWS on your local hard disk and enables you to work as same as IIS • PWS/IIS designate a master directory on the hard drive that contains all date and script file for use by Internet Server Page 5
Introduction to Server-Side Scripting Introduction to IIS/PWS • The default master directory is: \Inetpub • You can place your ASP file under subdirectory: \wwwroot (Example: C:\Inetpub\wwwroot\MyFirstAsp.asp) • IIS/PWS have built-in intelligence that knows to route a request for a Web page using HTTP to this directory. Page 6
Introduction to Server-Side Scripting ASP Requirements Page 7
Introduction to Server-Side Scripting What is ASP? • Stands for Active Server Pages • An ASP is a Web page that is processed by a web server • ASP is a Microsoft technology • ASP is a program that runs inside a web server (IIS/PWS) • An ASP file is just the same as an HTML file • An ASP file can contain text, HTML, XML, and scripts • An ASP file has the file extension ".asp" Page 8
Introduction to Server-Side Scripting What ASP can do? • 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 • Customize a Web page to make it more useful for individual users • Provides security since your ASP code can not be viewed from the browser • Since ASP files are returned as plain HTML, they can be viewed in any browser • Clever ASP programming can minimize the network traffic Page 9
Introduction to Server-Side Scripting How ASP file looks like? • At top of the ASP file, we have this line of code • You can place ASP code anywhere in the ASP file, BUT the code must be within its opening and closing delimiters tag <%@LANGUAGE = “JAVASCRIPT”%> <% // the rest of your ASP code %> Page 10
Introduction to Server-Side Scripting How ASP file looks like? <%@LANGUAGE=“JAVASCRIPT”%><% // it can be here %> <html> <head><title></title></head> <body> <% // it can be here %> </body> </html> <% // it can be here %> Page 11
Introduction to Server-Side Scripting How ASP file looks like? <%@LANGUAGE="JAVASCRIPT"%> <html> <head> <title>My First ASP Page</title> </head> <body> <% Response.Write("Hello World!"); %> </body> </html> Page 12
Introduction to Server-Side Scripting Form Processing Using ASP • Remember how to create a complete HTML form with input fields? <%@LANGUAGE="JAVASCRIPT" CODEPAGE="1252"%> <html> <head> <title>HTML and ASP</title> </head> <body> <form name="form1" method="post" action="login.process.asp"> <p>Username: <input name="username" type="text" id="username"></p> <p>Password: <input name="password" type="password" id="password"></p> <p><input name="Login" type="submit" id="Login" value="Login"></p> </form> </body> </html> Page 13
Introduction to Server-Side Scripting Form Processing Using ASP • Okay, save that file on the previous slide as login.asp • Notice that there is a value in action=“login.process.asp” It means, the login process will be done at another ASP file, which is login.process.asp <%@LANGUAGE="JAVASCRIPT" CODEPAGE="1252"%> <% if(Request.Form("Login") == "Login"){ var username, password; username = Request.Form("username"); password = Request.Form("password"); Response.Write("Username: " + username + "<br>"); Response.Write("Password: " + password); } %> Page 14
<%@LANGUAGE="JAVASCRIPT" CODEPAGE="1252"%> // as usual, code above is compulsory <% // code below means, if Login button is clicked, then the code block will // be executed if(Request.Form("Login") == "Login"){ // variables declaration var username, password; // 2 lines of codes below, show how to capture inputs from HTML // form username = Request.Form("username"); password = Request.Form("password"); // 2 lines of codes below, show how to display the values on the // web page Response.Write("Username: " + username + "<br>"); Response.Write("Password: " + password); } %> Page 15
Introduction to Server-Side Scripting Form Processing Using ASP • Why do we need to create a code if a button is clicked? • To execute a specific code once the button is clicked • Sometimes, in a single form, we have more than 1 buttons. Each 1 has its own specific (code|task) • By doing so, the system knows which code to be executed depending on which button has been clicked <% // code below means, if Login button is clicked, then the code block will // be executed if(Request.Form("Login") == "Login"){ // code block to be executed if button is clicked } %> Page 16
Introduction to Server-Side Scripting Form Processing Using ASP • Why do we need to create a code if a button is clicked? <% /* 1. code below means, if “Login” button is clicked, then the code block will be executed 2. “Login” name can be replaced with any name, depending on the name of button you specified in the form */ if(Request.Form("Login") == "Login"){ // code block to be executed if button is clicked } %> Page 17
Introduction to Server-Side Scripting Form Processing Using ASP • How to capture inputs from HTML form? • Similar to JavaScript, you need to declare variables to hold values captured from form • Request.Form(“<your_field_name>”)is used to capture the values before assign to variable • <your_field_name> is depending on names of input fields from text field, drop down list, text area, radio button, and checkbox <% // variables declaration var username, password; /* 2 lines of codes below, show how to capture inputs from HTML form */ username = Request.Form("username"); password = Request.Form("password"); %> Page 18
Introduction to Server-Side Scripting Form Processing Using ASP • How to display value on the web page? • Did you find any similarity with JavaScript? • In JavaScript, we use document.write() to display an output, • BUT in ASP, we use Response.Write()for the same purpose • To concatenate join several (text|codes), we use plus (+) symbol <% /* 2 lines of codes below, show how to display the values on the web page */ Response.Write("Username: " + username + "<br>"); Response.Write("Password: " + password); %> Page 19
Introduction to Server-Side Scripting Form Processing Using ASP • How to redirect from 1 page to another in ASP? • Sometimes, after we have successfully log into web application, we will be redirected to the menu page (for example) or any other pages • This can be done by using Response.Redirect(“<url_or_file>”) • “<url_or_file>” can be URL (website address) or ASP files <% if(Request.Form("Login") == "Login"){ Response.Redirect("http://www.google.com/"); } %> <% if(Request.Form("Login") == "Login"){ Response.Redirect("menu_administrator.asp"); } %> Page 20
Introduction to Server-Side Scripting JavaScript vs VBScript Page 21
Introduction to Server-Side Scripting Other Server Scripting Language • Scripting Language: programming language that allows control of one or more software applications • JavaScript • VBScript • Hypertext Preprocessor: PHP Page 22
Outline Server-Side Scripting • Adding server-side scripts into a web page • Inline or intersperse • Using ASP Response.Write to display text on a web page Page 23
Outline Build-in ASP Objects • The Response Object • The Request Object • The Session Object Page 24
Outline Build-in ASP Objects • The Application & Server Objects • Using Form Object Page 25
Outline Accessing Database with ASP and ADO • Introduction to ADO • Accessing data with ADO Page 26
Introduction to Server-Side Scripting ASP Objects • Response.Redirect(), Response.Write(), Request.Form() • You have seen those three ‘things’ in the previous slides • What are they? They are called ASP Objects • We have: • ASP Response Object • ASP Request Object • ASP Server Object • And few others Page 27
Introduction to Server-Side Scripting ASP Response Objects Page 28
Introduction to Server-Side Scripting ASP Response Objects Page 29
Introduction to Server-Side Scripting ASP Response Objects Page 30
Introduction to Server-Side Scripting ASP Response Objects Page 31
Introduction to Server-Side Scripting ASP Request Objects Page 32
Introduction to Server-Side Scripting ASP Request Objects Page 33
Introduction to Server-Side Scripting ASP Server Objects Page 34
Introduction to Server-Side Scripting ASP Server Objects Page 35
Question? Page 36
Knuckles (2001). Introduction to Interactive Programming on the Internet using HTML & Javascript. John Wiley & Sons, Inc. http://www.w3schools.com/asp/default.asp Bibliography (Book) Bibliography (Website) Page 37