18 – Web applications: Server-side code (ASP)

Slides:



Advertisements
Similar presentations
Mark Dixon Page 1 16 – Passing Data between pages: Forms, Sessions, & Query Strings.
Advertisements

CPSC 203 Introduction to Computers Tutorial 59 & 64 By Jie (Jeff) Gao.
ASP Tutorial. What is ASP? ASP (Active Server Pages) is a Microsoft technology that enables you to make dynamic and interactive web pages. –ASP usually.
Mark Dixon, SoCCE SOFT 131Page 1 20 – Web applications: HTML and Client-side code.
Mark Dixon Page 1 02 – Dynamic HTML (client-side scripting)
Mark Dixon Page 1 15 – Web applications: Server-side code (ASP)
Mark Dixon, SoCCE SOFT 131Page 1 16 – Web applications: HTML and Client-side code.
Introduction to Active Server Pages
Mark Dixon, SoCCE SOFT 131Page 1 16 – Passing Data between pages: Sessions, Query Strings, & Self Posting.
Mark Dixon Page 1 20 – Web applications: Writing data to Databases using ASP.
Mark Dixon Page 1 15 – Web applications: Server-side code (ASP)
Mark Dixon, SoCCE SOFT 131Page 1 19 – Web applications: Server-side code (ASP)
Mark Dixon, SoCCE SOFT 131Page 1 08 – Web applications: HTML and ActiveX controls.
Chapter 7 Working with Files.
1 CS 3870/CS 5870 Static and Dynamic Web Pages ASP.NET and IIS.
Mark Dixon Page 1 19 – Passing Data between pages: Forms, Sessions, & Query Strings.
1 CS 3870/CS 5870 Static and Dynamic Web Pages ASP.NET and IIS.
ASP.NET Dr. Ralph Westfall May, Web Development Problem HTML designed to display static pages only interactive when user clicks links  can’t provide.
M Dixon 1 Web-Application Development Workshop. M Dixon 2 Session Aims & Objectives Aims –to introduce the main concepts involved in creating web-applications.
CS441 CURRENT TOPICS IN PROGRAMMING LANGUAGES LECTURE 5_1 George Koutsogiannakis/ Summer
Web Programming: Client/Server Applications Server sends the web pages to the client. –built into Visual Studio for development purposes Client displays.
Mark Dixon Page 1 3 – Web applications: Server-side code (JSP)
10/5/2015CS346 PHP1 Module 1 Introduction to PHP.
Mark Dixon 1 22 – Web applications: Writing data to Databases using ASP.Net.
Mark Dixon Page 1 23 – Web applications: Writing data to Databases using ASP.
Web Design and Development for E-Business By Jensen J. Zhao Copyright 2003 Prentice Hall, Inc. Web Design and Development for E-Business Jensen J. Zhao.
CPSC 203 Introduction to Computers Lab 23 By Jie Gao.
ASP Introduction Y.-H. Chen International College Ming-Chuan University Fall, 2004.
Mark Dixon 1 18 – Web applications: Server-side code (ASP.Net)
Mark Dixon Page 1 18 – Web applications: Server-side code (ASP)
Mark Dixon Page 1 18 – Web applications: Server-side code (PhP)
ASP/ASP.NET: Tricks and Tips How to get Microsoft’s Programming Language to work for you By Wade Tripp Park University
Mark Dixon 1 03 – Passing Data between pages: Forms, Sessions, & Query Strings.
Lecture Note 1: Getting Started With ASP.  Introduction to ASP  Introduction to ASP An ASP file can contain text, HTML tags and scripts. Scripts in.
1 After completing this lesson, you will be able to: Transfer your files to the Internet. Choose a method for posting your Web pages. Use Microsoft’s My.
Mark Dixon Page 1 Web-Application Development Workshop.
Intro to PHP IST2101. Review: HTML & Tags 2IST210.
Mark Dixon Page 1 21 – Web applications: Writing data to Databases using ASP.
Mark Dixon, SoCCE SOFT 131Page 1 24 – Datatypes and Object Association.
M Dixon 1 Web-Application Development Workshop. M Dixon 2 Session Aims & Objectives Aims –to introduce the main concepts involved in creating web-applications.
Mark Dixon 1 19 – Passing Data between pages: Forms, Sessions, & Query Strings.
ASP. What is ASP? ASP stands for Active Server Pages ASP is a Microsoft Technology ASP is a program that runs inside IIS IIS stands for Internet Information.
M Dixon 1 Tech HTML. M Dixon 2 Admin Attendance Register: –log in to your profile.
Mark Dixon Page 1 15 – Web applications: Server-side code (ASP)
Web Authoring with Dreamweaver. Unit Objectives  Be able to define keywords: HTML, HTTP (protocol), browser, web server, client/server, tag, attribute,
PHP Form Processing * referenced from
IST 210: PHP Basics IST 210: Organization of Data IST2101.
111 State Management Beginning ASP.NET in C# and VB Chapter 4 Pages
ASP – Web Programming Class  Ravi Anand. ASP – Active Server Pages What is ASP? - Microsoft Technology - Can Run using IIS/PWS/Others - Helps us create.
Web Programming Language
Introduction to HTML.
ASP.NET Forms.
9 – Web applications: Server-side code (ASP)
Web Concepts Lesson 2 ITBS2203 E-Commerce for IT.
Active Server Pages Computer Science 40S.
Web Forms, HTML, and ASP.NET
Introduction to ASP By “FlyingBono” 2009_01 By FlyingBono 2009_01
21 – Web applications: Server-side code (ASP)
18 – Web applications: Server-side code (PhP)
17 – Modular Design in ASP.
Dynamic Web Page A dynamic web page is a kind of web page that has been prepared with fresh information (content and/or layout), for each individual viewing.
12 – Passing Data between pages: Forms, Sessions, & Query Strings
Client side & Server side scripting
WEB PROGRAMMING JavaScript.
Integrating JavaScript and HTML
Module 1 Introduction to PHP 11/30/2018 CS346 PHP.
Static and Dynamic Web Pages
17 – Persistent data storage: relational databases and ADO
Programming with Microsoft Visual Basic 2008 Fourth Edition
Introduction to JavaScript
Presentation transcript:

18 – Web applications: Server-side code (ASP)

Session Aims & Objectives To introduce the fundamental ideas involved in server-side code Objectives, by end of this week’s sessions, you should be able to: create an asp web-page, including: HTML, and server-side VB

Example: Logon (analysis) SPECIFICATION User Requirements protection from fraud and invasion of privacy Software Requirements Functional: logon page, user must type name and password following pages can only be accessed after successful logon Non-functional should be very difficult to hack hotmail, Amazon, University portal, utility bills (gas, electricity, phone, internet), Travel (flights, ferry, car rental)

Example: Logon (design) Restrict access to home page

Example: Logon (code v1) Logon.htm Using Client-side VB Script <html> <head><title></title></head> <body> Please logon:<br /> <input id="txtUserName" type="text" /><br /> <input id="txtPassWord" type="text" /><br /> <input id="btnLogon" type="submit" value="Logon" /> <p id="msg"></p> </body> </html> <script language="vbscript"> Sub btnLogon_OnClick() Dim un Dim pw un = txtUserName.value pw = txtPassWord.value If un = "mark" And pw = "soft131" Then window.navigate "home.htm" Else msg.innerText = "Login details incorrect." End If End Sub </script> Home.htm <html> <head><title>My Home page</title></head> <body> <p> Welcome to my home page.<br /> <img src="YouAreHere.jpg" /> </p> </body> </html>

Example: Login (Problem) View Source – shows client-side script: Reveals both username & password

Web Hardware and Software Server Client network connection Browser Application (MS Explorer, FireFox, Opera) Web-server Application (MS IIS, Apache)

Request-Response Cycle Browser Application (MS Explorer, Firefox) Web-server Application (MS IIS, Apache) Logon.htm Response <html> <head><title></title></head> <body> Please logon:<br /> <input id="txtUserName" type="text" /><br /> <input id="txtPassWord" type="text" /><br /> <input id="btnLogon" type="submit" value="Logon" /> <p id="msg"></p> </body> </html> <script language="vbscript"> Sub btnLogon_OnClick() Dim un Dim pw un = txtUserName.value pw = txtPassWord.value If un = "mark" And pw = "soft131" Then window.navigate "home.htm" Else msg.innerText = "Login details incorrect." End If End Sub </script> Client-side code: Code sent to Client Interpreted by browser

Server-side Script (what) ASP – active server pages code not sent to client code secure (can't be viewed by client) executed on server takes time – request-response cycle requires server software (e.g. IIS) ASP pages will NOT work by double clicking on file

Example: Date ASP code: .aspx (not .htm) VB (not vbscript) Date.aspx ASP code: .aspx (not .htm) VB (not vbscript) variables have type Now is current date and time (on server) runat="server" gives server code access to object <script language="VB" runat="server"> Sub Page_Load() Dim s As String s = "The date today is " s = s & Format(Now, "ddd d MMM yyyy") parD.InnerText = s s = "The time now is " s = s & Format(Now, "HH:mm") parT.InnerText = s End Sub </script> <html> <head><title>Today's Date</title></head> <body> <p id="parD" runat="server"></p> <p id="parT" runat="server"></p> </body> </html>

Request-Response Cycle date.aspx Request Browser Application (MS Explorer, Firefox) Web-server Application (MS IIS, Apache) <script language="VB" runat="server"> Sub Page_Load() Dim s As String s = "The date today is " s = s & Format(Now, "ddd d MMM yyyy") parD.InnerText = s s = "The time now is " s = s & Format(Now, "HH:mm") parT.InnerText = s End Sub </script> <html> <head><title>Today's Date</title></head> <body> <p id="parD" runat="server"></p> <p id="parT" runat="server"></p> </body> </html> Response <html> <head><title>Today's Date</title></head> <body> <p id="parD">The date today is Mon 9 Feb 2009</p> <p id="parT">The time now is 00:57</p> </body> </html> Server-side code: run on server (never sent to Client)

View Source Code executed at server View, Source – does not show code: code is never sent to client View, Source – does not show code:

Data Types Variant – all types of data slow, memory hungry Boolean – true or false (on/off, yes/no) Integer – whole numbers (-32768 to 32768) Long – whole numbers (large) Single – decimal numbers Double – decimal numbers (more precise) String – text Object – object instances

Data Type Selection Number of e.g. 4 Integer/Long Rooms Height e.g. 1.87m Single/Double Surname e.g. Smith String Car Reg e.g. XY55 ABC String

Using data types Variable declaration Dim x As Long Parameters Sub Thing(boo As String, y As Long) Functions Function IsTall() As Boolean

Question: Data types Declare a variable to store: Dim weight As Double an animal's weight in kg (e.g. 34.6) whether a person has a driving licence or not the title of a book a phone number (e.g. 01752 586225) Dim weight As Double Dim licence As Boolean Dim title As String Dim phone As String

Example: AddNum (client-side) AddNum.htm <html> <head><title></title></head> <body> <input id="txtN1" type="text" /><br /> <input id="txtN2" type="text" /><br /> <input id="btnAdd" type="submit" value="Add" /> <p id="parRes"></p> </body> </html> <script language="vbscript"> Sub btnAdd_onClick() Dim N1 Dim N2 N1 = txtN1.Value N2 = txtN2.Value parRes.InnerText = N1 + CDbl(N2) End Sub </script>

Example: AddNum (server-side) AddNum.aspx <script language="VB" runat="server"> Sub Page_Load() Dim N1 As Double Dim N2 As Double If Request.Form("btnAdd") > "" Then N1 = txtN1.Value N2 = txtN2.Value parRes.InnerText = N1 + N2 End If End Sub </script> <html> <head><title></title></head> <body> <form runat="server"> <input id="txtN1" type="text" runat="server" /><br /> <input id="txtN2" type="text" runat="server" /><br /> <input id="btnAdd" type="submit" value="Add" runat="server" /> <p id="parRes" runat="server"></p> </form> </body> </html> If btnAdd clicked input tags inside form submit button: refreshes page (sending data to server)

Client-side vs. Server-side Code AddNum.htm AddNum.aspx <html> <head><title></title></head> <body> <input id="txtN1" type="text" /><br /> <input id="txtN2" type="text" /><br /> <input id="btnAdd" type="submit" value="Add" /> <p id="parRes"></p> </body> </html> <script language="vbscript"> Sub btnAdd_onClick() Dim N1 Dim N2 N1 = txtN1.Value N2 = txtN2.Value parRes.InnerText = N1 + CDbl(N2) End Sub </script> <script language="VB" runat="server"> Sub Page_Load() Dim N1 As Double Dim N2 As Double If Request.Form("btnAdd") > "" Then N1 = txtN1.Value N2 = txtN2.Value parRes.InnerText = N1 + N2 End If End Sub </script> <html> <head><title></title></head> <body> <form runat="server"> <input id="txtN1" type="text" runat="server" /><br /> <input id="txtN2" type="text" runat="server" /><br /> <input id="btnAdd" type="submit" value="Add" runat="server" /> <p id="parRes" runat="server"></p> </form> </body> </html> Both use VB Script language (i.e. Sub, If, Dim, For, etc.)

Example: Apples Apples.aspx <script runat="server" language="VB"> Sub Page_Load() If Request.Form("btnGo") > "" Then parRes.InnerHtml = parRes.InnerHtml & "<img src='Apple.gif' />" End If End Sub </script> <html> <head><title>Apples</title></head> <body> <form runat="server"> <input id="btnGo" type="submit" value="Go" runat="server" /> <p id="parRes" runat="server"></p> </form> </body> </html>

Errors vbscript cannot run at server (should be VB) <script language="vbscript" runat="server"> Sub Page_Load() Dim s As String s = "The date today is " s = s & Format(Now, "ddd d MMM yyyy") parD.InnerText = s s = "The time now is " s = s & Format(Now, "HH:mm") parT.InnerText = s End Sub parD.innerText = "" </script> <html> <head><title>Today's Date</title></head> <body> <p id="parD" runat="server"></p> <p id="parT"></p> </body> </html> vbscript cannot run at server (should be VB) Declaration expected (assignment must be in sub) parT is undefined (should have runat="server")

Running your ASP pages within Visual Studio Run (play) button (F5) only available to you on development PC using Internet Information Services (IIS) makes PC a server page available to all computers on internet

Add/Remove Windows Components IIS - Installing IIS / personal web server on Windows CD Start, Settings, Control Panel, Add/Remove Programs Add/Remove Windows Components IIS

IIS: Enabling/Disabling Start, Settings, Control Panel, Administrative Tools, Internet Services Manager Start Stop

IIS: Exposing pages Put ASP pages in: Execute pages by putting: C:\INetPub\wwwRoot (this part of hard disk exposed to outside world) Execute pages by putting: localhost (in web browser, e.g. IE, means local machine) ASP pages don't work by double-clicking

IIS – Date.asp C:\INetPub\wwwRoot\Date.aspx localhost/test/date.aspx

Tutorial Demo: First.htm Create a new text file in web server's root folder: Open Windows Explorer (My Computer) Ensure folders are displayed Navigate to: C:\INetPub\wwwRoot Right click on the background Click New Click Text Document Rename file Right click Click Rename Type file name (First.htm) Click Yes (when asked to confirm change of extension)

Tutorial Demo: First.htm Put some code in the file: Right Click on the file Click Open with Notepad Type the following code: <html> <head><title></title></head> <body> Hello world! </body> </html> View the file Open Internet Explorer Navigate to: http://localhost/First.htm

Tutorial Demo: First.htm View each others' pages In your browser, type: http://SMB109xx/First.htm where xx is the machine number of someone else's computer you should see their page See changes take effect: One person change their page (colour, etc.) Other person refresh browser you should see changes

Tutorial Demo: Date.aspx Create a web-site page (same as before): Open Visual Studio 2005 Click the File menu Click the New Web Site… item Click the Browse button Select an existing folder to put your work in Type the name of a subfolder Click Yes to create the subfolder Click Empty Web Site Click OK

Tutorial Demo: Date.aspx Create a new aspx page: Click Add New Item icon on tool bar Double Click html page icon Right click file Click Rename item Change name (date.aspx) Click Yes to confirm extension change Paste the code in from the lecture slides Click the Run button

Tutorial Exercise: Login (client-side) LEARNING OBJECTIVE: see how vulnerable client-side code is Task 1: Get the Login (v1) example from the lecture working. Task 2: Use view source – you should be able to see the code.

Tutorial Exercise: Date LEARNING OBJECTIVE: create an ASP page, including HTML and server-side VB Script Task 1: Get the Date example from the lecture working. Task 2: Add code that displays good morning/afternoon/evening/night, depending on the time of day.

Tutorial Exercise: Student Loan LEARNING OBJECTIVE: create an ASP page, including HTML and server-side VB Script from scratch to solve a problem Task 1: Create a web page that allows the user to enter their salary and the computer calculates the annual and monthly payments for their student loan. Hint: Use your client-side code (from term 1), and the AddNum example from the lecture.

Tutorial Exercise: Login (client-side) LEARNING OBJECTIVE: create an ASP page, including HTML and server-side VB Script from scratch to solve a problem Task 1: Create a login page that uses server-side code to check the username and password entered by the user. Hint: Use the AddNum example as inspiration. Hint2: Use the following code to send the user to the homepage: Response.Redirect("Home.htm") Task 2: Use view source – you should NOT be able to see the code.

Tutorial Exercise: Apples LEARNING OBJECTIVE: use variables with specific data types in ASP code Task 1: Get the apples example (from the lecture) working. Task 2: Modify your program so that the user enters a number, and the code adds that number of apple images. Task 3: Modify your program so that the user enters another number, and the code adds a new line tag for that number of apples. Hint: Within the loop divide the number of apples by the second number, if the result is a whole number add a new line tag.