1 / 23

DT221/3 Internet Application Development

DT221/3 Internet Application Development. Active Server Pages & IIS Web server. Readability of ASP pages. Always always always ensure that code is: INDENTED COMMENTED ID BLOCK Indented - to reflect level of the code <html> <head>ajsdlkfjads etc

Download Presentation

DT221/3 Internet Application Development

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. DT221/3 Internet Application Development Active Server Pages & IIS Web server

  2. Readability of ASP pages • Always always always ensure that code is: • INDENTED COMMENTED ID BLOCK • Indented - to reflect level of the code <html> • <head>ajsdlkfjads etc • 2) Well commented. Comments in ASP appear as‘ the next subroutine will appear as…‘ followed by a function which will calculate.. • Comments in HTML appear as <!--- this is a commentb --> • HTML comments will be visible by view source in browser, ASP comments won’t.

  3. Readability of ASP pages 3) Titled: At the top of each ASP page, should have an ID block explaining who write the script, date, script name, description and any revisions. Can use either ASP or HTML comments (depending on whether clients should be able to see the ID block) <%@ Language = VBScript %> <%Option Explicit %> <% ' ********************************************* ' *** Script name: conversion.asp *** ' *** Author: Jimmy Saville *** ‘ *** Date: July 7th 2003 *** ‘ *** Desciption: whatever it does.. *** ‘ *** Revisions: *** ‘ *** August 8th 2003: added subroutine *** '************************************************ %> etc

  4. ASP Syntax • ASP files for web output usually contain HTML tags. • Any scripts intended for execution by the server must be between <% and %> to distinguish them from HTML • The ASP engine looks specifically for code between • <% and %> - this code will then be parsed by the ASP engine. The remainder will be ignored

  5. ASP Scripting languages • The default language for code is VBScript, although other languages can be used e.g. JavaScript, Jscript. • To set the language , use a language specification at the first line of the page using the @Language declarer: • <%@ language = “Jscript” %> • <html> etc etc • You don’t have to set the language for VBSCript as it’s the default – but it’s good practice to include it. • All examples here are in VBScript

  6. ASP- simple example <%@ LANGUAGE = VBScript%> <% Option Explicit %> <html><body><%dim namename="John Wayne"response.write("My name is: " & name)%></body></html> • Using View Source at the browser will show HTML only. • Dim used to create a variable “name” • Write methods of Response object used to output • ‘Option Explicit’ enforces all variables to be declared. Good practice

  7. ASP – Declaring variables • To declare a variable – use Dim e.g Dim Actors • Variables are of type variant (You don’t have to explicitly state string, integer etc.) • To declare an array add the array size on. e.g. Dim Actors(3) • First element of the array has an index 0 e.g. Actors(0) = “Tom” • Function Ubound determines the upper index of the arraye.g. Ubount(Actors) has a value of 4

  8. ASP – Declaring variables - example <@ LANGUAGE=VBSCRIPT %> <%   'First we will declare a few variables.Dim SomeText  Dim SomeNum  'Next we will assign a value to these.  SomeText = "ASP is great!"  SomeNum = 1  'Note that SomeText is a string and SomeNum is numeric.  'Next we will display these to the user.  Response.Write(SomeText)  Response.Write(SomeNum)  'You may also add (append) HTML code to these.  Response.Write ("Right now you are thinking that " & SomeText)%>

  9. ASP- Array example <%@ LANGUAGE = VBScript %> <% Option Explicit %> <html> …. <body> A list of the best actors in the film><br> <% Dim Actors(3), i Actors(0) = “Tom Cruise” Actors(1) = “Cillian Murphy” Action(2) = “Julia Roberts” For I = 0 to Ubound(Actors) OutStr = OutStr + “:” + Actors(I) + “<br>” Next Response.Write(OutStr) %> </body> etc Do not have to include the Counter variable as in VB.

  10. ASP Object Model • ASP has seven built-in objects. Each of these objects has a set of properties , methods and collections that can be used to enhance ASP pages: • Request(Has a “form” collection to hold data entered into a form) • Response(Has a “write method” to output to web page) • Session • Server • Application • ObjectContext • ASPError(new)Detailed info at : http://www.asp101.com/resources/aspobject.asp Data structures where number of elements is variable (unlike arrays)

  11. ASP Object Model - Request • Request - supplies information regarding the request the user sends to the Web application • Request objects includes the following collections: • Form (values from the form elements sent by the browser).Any <input> elements in a HTML <form> are available to to ASP using Request.Form (elementname) IF the “post” request method has been used • QueryString – values of the variables in a HTTP query string, which is data sent to the server in the URL I.e.www.blahblah.com?id=2347&name=jimQueryString is populated if the “get” method is used

  12. ASP Object Model – Request –HTML Form that collects 3 pieces of info <html> .. header etc <body> <font color = blue size = 4 face = arial> <form method = "post" Action = "processForm.asp"> Your name: <input type = text name = txtName> <br> Your favourite colour: <input type = text name = txtColour> <br> Your favourite film: <input type = text name = txtFilm> <br> <input type = "submit" value = "Click to submit information" </form> </font> </body> </html> etc

  13. ASP Object Model – Request – output form content onto a web page <html etc… <body> <font color = blue size = 4 The data entered into the form was: <br> Name = <%response.write(Request.Form("txtName"))%> <br> Favourite colour = <%=Request.Form("txtColour")%> <br> Favourite Film = <%=Request.Form("txtFilm")%> <br> </font> </body> </html> etc The Form collection of the Request object holds all the request parameters Note: can use a short cut to output onto the web page from a script. Instead of Response.write can just use <%= %> . Both ways shown here.

  14. ASP: Subroutines and functions • Use subroutines and functions in ASP pages in order to economise on code.. I.e to enable ‘modules’ of code to be used and reused • Subroutines define a series of steps that accomplishes some task, but does not usually return a value • Functions accomplish a series of steps And usually return a single value

  15. ASP : Subroutines - example <html> <head> <% sub calculate(num1,num2) response.write(num1*num2) end sub %> </head> <body> The product of the two numbers entered is: <p> <% dim x dim y x = request.form("firstNum") y = request.form("secondNum")%> Result: <%call calculate(x,y)%> </p> </body> etc Subroutine always starts with Sub, ends with End Sub use “Call” Arguments passed to subroutine (num1, num2)

  16. ASP : Function example <html> etc <head> <% Function retailPrice(price) dim tax tax=price*.09 retailPrice =price+tax end Function %> </head> etc.. <body> etc <% dim y y = retailPrice(request.form("netprice")) Response.write(“The retail price includig tax " &y) %> etc </body> </html> Function always startswith Function and ends with End function Make sure that output is explicitly named in the function Retrieves a netprice and calculates the retail price, using the function

  17. ASP- reusable code • Very common in a web application to need to include common code such as headers/footers/navigation bars, subroutines etc across more than one Web page. • ASP allows the use of a Server Side Include directive called INCLUDE, which includes the contents of another file into the current file. It’s the only SSI directive allowed in ASP (e.g. #echo, #exec etc are not allowed) • Must surround the ‘include’ SSI directive as a HTML comment: • Syntax: • <!== #include attribute = value - ->

  18. ASP- reusable code - example • <!-- #include file = “include\header.html --> • Will include the contents of header.html into the ASP page. It assumes header.html is in subdirectory include, relative to to the current directory.Note: good practice to place all ‘include’ code into a single directory.. called include • <!-- #include virtual = “/testdir/header.html --> • Will include the contents of header.html into the ASP page. It assumes header.html is the files virtual path relative to the server root directory. It’s not concernted with current directory.

  19. Comparing ASP versus JSP • Similarities • Both are scripting based technologies • Both enable dynamic web pages • Both help to separate the page design from the programming logic • Both provide an alternative to CGI Scripts, enabling easier and fast page development and deployment • Compilation: ASP was originally interpreted but ASP.netuses compiled code, similar to JSP

  20. Using ASP versus JSP ? • For a development project, how to choose whether ASP versus JSP may be used? (assuming PHP and others have been excluded!) • What technology is used already? ASP is usually used with Microsoft’s IIS, which requires Windows operating system - tied into Microsoft technology. Whereas JSP is platform independent - check whether the company is tied into any particular vendor products already that will guide decision> • ASP JSP • Web Server Microsoft IIS Any web server, include apache, Netscape & IIS • Platforms Microsoft Windows Most popular platforms

  21. Using ASP versus JSP ? • Development skills - JSP support Javascript, Java code and tags (custom and JSLT). ASP supports both Vbscript and JavaScript. Need to check which skills are already available in the development team • Simplicity? ASP was traditionally regarded as simpler to develop (VBScript) than JSP (using Java code). However, the growth in use of re-usable tag based actions for JSP is changing this. If the company is open to using JSP tags, both are relatively simple. • Re-usability across platform – JSP will be portable across platforms, ASP generally is not.

  22. Using ASP versus JSP ? • Debugging/error resolution – In JSP, the code is converted into Java servlets in the background – any runtime errors refer to the servlet code which can make it difficult to find the error. ASP is not translated – so any line references are within the ASP page itself. • Code re-use - Both allow common code to be taken out and re-used. JSP, with its use of custom and JSLT tags, is probably superior on this. Use of tags also enables easy global changes without individual page change. • Performance – JSP traditionally considered faster as code is precompiled into servlets. However, now that ASP is part of ASP.Net which is also compiled  comparable on performance.

  23. Using ASP versus JSP ? • Open source – JSP (and other java based technologies from Sun) are developed with input from the Java community. ASP is proprietary. Cost/quality/vendor support implications.

More Related