Download presentation
Presentation is loading. Please wait.
1
Mark Dixon, SoCCE SOFT 131Page 1 19 – Web applications: Server-side code (ASP)
2
Mark Dixon, SoCCE SOFT 131Page 2 Session Aims & Objectives Aims –To introduce the fundamental ideas involved in server-side code Objectives, by end of this week’s sessions, you should be able to: –add dynamic server-side functionality, using VB Script
3
Mark Dixon, SoCCE SOFT 131Page 3 network connection Web Hardware and Software Client Server Browser Application (MS Explorer, Netscape) Web-server Application (MS IIS, Apache)
4
Mark Dixon, SoCCE SOFT 131Page 4 Request-Response Cycle Browser Application (MS Explorer, Netscape) Web-server Application (MS IIS, Apache) http://mdixon.soc.plym.ac.uk/ Request Mark Dixon's web site Mark Dixon's web site Welcombe to my web server. Please select from the following list: Soft131: Introduction to programming for Multimedia and Internet applications. Response
5
Mark Dixon, SoCCE SOFT 131Page 5 Server-side Script (what) ASP – active server pages –executed on server takes time – request-response cycle requires server software (e.g. IIS) –not sent to client secure (can't be viewed by client) –results (response) sent to client pages will NOT work by double clicking on file
6
Mark Dixon, SoCCE SOFT 131Page 6 Server-side Script (IIS) IIS / personal web server on Windows CD Start, Settings, Control Panel, Add/Remove Programs Add/Remove Windows Components IIS
7
Mark Dixon, SoCCE SOFT 131Page 7 Enabling/Disabling IIS Start, Settings, Control Panel, Administrative Tools, Internet Services Manager Stop Start
8
Mark Dixon, SoCCE SOFT 131Page 8 Server-side Script (how) ASP code: –.asp (not.htm) –between –Response object: page sent back to client write method: adds text to response object –Date() function: current date (server) Today's date The date today is <% Response.Write Date() & " " %> The time is currently <% Response.Write Time() & " " %> Date.asp
9
Mark Dixon, SoCCE SOFT 131Page 9 Form Submission action attribute submit button Login Please login: Username: Password: Login.htm
10
Mark Dixon, SoCCE SOFT 131Page 10 Form Processing Login <% If Request.Form("txtUserName") = "George" Then Response.Write "Login successful." Else Response.Write "Invalid user name." End If %> LoginCheck.asp
11
Mark Dixon, SoCCE SOFT 131Page 11 View Source Code executed at server –code is never sent to client View, Source – does not show code:
12
Mark Dixon, SoCCE SOFT 131Page 12 Code Execution Login <% If Request.Form("txtUserName") = "George" Then Response.Write "Login successful." Else Response.Write "Invalid user name." End If %> LoginCheck.asp Server SW (IIS) Login Invalid user name. Response
13
Mark Dixon, SoCCE SOFT 131Page 13 Maintaining State between pages Problem –want to protect all pages from unauthorised access –need to store record of successful login Variables –only persist for duration of page
14
Mark Dixon, SoCCE SOFT 131Page 14 Maintaining State Self Posting Session object –exists for current session –clears if user closes brower –clears after 20 mins of inactivity Cookies –stored on users hard drive –persists between sessions Database/file –stored on server –persists between sessions
15
Mark Dixon, SoCCE SOFT 131Page 15 Self Posting Multiply <% Dim tmpRes Dim tmpNum1 Dim tmpNum2 If Request.Form("txtNum1") <> "" And Request.Form("txtNum2") <> "" Then tmpNum1 = CDbl(Request.Form("txtNum1")) tmpNum2 = CDbl(Request.Form("txtNum2")) tmpRes = tmpNum1 * tmpNum2 End If %> > Multiply.asp Post to Self Only do calc if first load
16
Mark Dixon, SoCCE SOFT 131Page 16 Session Object Login <% If Request.Form("txtUserName") = "George" Then Session("LoginOK") = "Yes" Response.Redirect "Home.asp" Else Session.Abandon If Request.Form("txtUserName") <> "" Then Response.Write "Invalid user name, please try again." End If %> Please login: Username: Password: Login.asp Session variable –all strings Abandon method –deletes all session variables Redirect method –redirects browser to specified page
17
Mark Dixon, SoCCE SOFT 131Page 17 Session Object <% If Session("LoginOK") <> "Yes" Then Response.Redirect "Login.asp" End If %> Home Page Welcome to my home page. Home.asp ASP code to check for successful login
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.