Other Web Programming Languages Serverside scripting Creates dynamic

  • Slides: 32
Download presentation
Other Web Programming Languages

Other Web Programming Languages

Server-side scripting Creates dynamic web pages using Information sent by clients Information stored on

Server-side scripting Creates dynamic web pages using Information sent by clients Information stored on the server Information stored in the server’s memory Information from the Internet

ASP. NET A compiled. NET programming platform and technology that can be used on

ASP. NET A compiled. NET programming platform and technology that can be used on a server to create Web applications Takes advantage of Microsoft’s. NET framework Thousands of classes Supports over 25 programming languages, incl. Visual Basic. NET C# JScript (not Javascript because of trademark issues)

. NET Overview. NET strategy: independence from a specific programming language Any. NET compatible

. NET Overview. NET strategy: independence from a specific programming language Any. NET compatible language is ok Promotes software reuse Porting (adapting) existing software components to . NET Visual Basic 6 or Visual C++ 6

. NET Framework The heart of. NET strategy Manages and executes applications Provides a

. NET Framework The heart of. NET strategy Manages and executes applications Provides a class library (Framework Class Library or FCL) Contains reusable components for programmers to use in their applications Enforces security Supplies many other programming capabilities Windows only (so far)

ASP. NET Active Server Pages Create multi-tier, database-intensive applications by employing . NET’s object-oriented

ASP. NET Active Server Pages Create multi-tier, database-intensive applications by employing . NET’s object-oriented languages and the FCL’s Web controls (ASP. NET server controls) File types. aspx contain the GUI of a page and may also contain the logic of the page Often has a corresponding code-behind file that contains a class written in a. NET language

Setup Requires Microsoft. NET Framework and the. NET Framework System Development Kit (SDK) SDK

Setup Requires Microsoft. NET Framework and the. NET Framework System Development Kit (SDK) SDK provides tools, examples, reference files and tutorials

<%@ Page Language="JScript" %> <html> <head> <title>A Simple ASP. NET Example</title> <style type =

<%@ Page Language="JScript" %> <html> <head> <title>A Simple ASP. NET Example</title> <style type = "text/css"> td { background-color: black; color: yellow } strong { font-family: arial, sans-serif; font-size: 14 pt; color: blue } p { font-size: 14 pt } </style> <script runat = "server" language = "JScript"> var day. And. Time : Date. Time = Date. Time. Now; </script> </head> <body> <strong>A Simple ASP. NET Example</strong> <p> <table border = "6"> <tr> <td> It is <% Response. Write(day. And. Time. To. Short. Time. String() ); %> </td> <td> on <% Response. Write( day. And. Time. To. Short. Date. String() ); %> </td> </tr> </table> </p> </body> </html>

ASP. NET Example The @Page directive specifies information needed by the CLR to proces

ASP. NET Example The @Page directive specifies information needed by the CLR to proces the file Language attribute specifies JScript. NET as the scripting language --> indicates which CLR compiler to use Scripting delimiters <% and %> --> delimit the scripting code that is compiled and executed on the server, not the client “runat” indicates that the script should be processed on the server

Web Forms ASPX files are usually referred to as Web Forms or Web Form

Web Forms ASPX files are usually referred to as Web Forms or Web Form Pages --> process form input Web controls: HTML server controls Web server controls Validation controls (validators) User controls

Web Controls

Web Controls

Web Controls

Web Controls

Web Controls

Web Controls

<%@ Page Language="JScript" %> </table> <html> <head> <title>Validate Fields</title> <script language = "JScript" runat

<%@ Page Language="JScript" %> </table> <html> <head> <title>Validate Fields</title> <script language = "JScript" runat = "server"> <br /> Do you like ice cream? function submit. Button_Click( sender : Object, events : Event. Args ) : void { if ( Is. Post. Back ) { if ( ice. Cream. Selected. Item == "Yes" ) { message. Text = name. Text + " likes ice cream. "; } else { message. Text = name. Text + " does not like ice cream. "; } } <asp: Radio. Button. List id = "ice. Cream" runat = "server"> <asp: List. Item>Yes</asp: List. Item> <asp: List. Item>No</asp: List. Item> </asp: Radio. Button. List> <br /> How many scoops would you like? (0 -45) <asp: Text. Box id = "scoops" runat = "server" /> <br /> <asp: button text = "Submit" On. Click = "submit. Button_Click" runat = "server"/> <asp: Range. Validator Control. To. Validate = "scoops" Minimum. Value = "0" Maximum. Value = "45" Type = "Integer" Enable. Client. Script = "false" Text = "We cannot give you that many scoops. " runat = "server" /> } // end submit. Button_Click </script> </head> <body> <form action = "validation. aspx" method = "post" runat = "server"> <center> <h 1> <asp: label id = "message" runat = "server"/> </h 1> <table> </center> <tr> <td> </form> Name: <asp: textbox id = "name" runat = "server"/> </body> </td> </html> <td> <asp: Required. Field. Validator id = "required" Control. To. Validate = "name" Display = "Static" runat = "server"> Please enter your name. </asp: Required. Field. Validator> </td> </tr>

ASP. NET ASPX pages usually contain a form that, when submitted, causes the current

ASP. NET ASPX pages usually contain a form that, when submitted, causes the current page to be requested again --> postback ASP. NET provides classes and built-in functionality to manipulate XML files as well Connecting to a Database in ASP. NET: Use an Ole. Db. Data. Reader: an object that reads data from a database

<%@ Page Language="JScript" %> <%@ Import Namespace="System. Data" %> <%@ Import Namespace="System. Data. Ole.

<%@ Page Language="JScript" %> <%@ Import Namespace="System. Data" %> <%@ Import Namespace="System. Data. Ole. Db" %> <%@ Register Tag. Prefix="Header" Tag. Name="Image. Header" Src="image. Header. ascx" %> data. Base. Connection ); var data. Reader = data. Base. Command. Execute. Reader(); // while we read a row from result of // query, add first item to drop down list while ( data. Reader. Read() ) <html> name. List. Items. Add( data. Reader. Get. String( 0 ) + <body> ", " + data. Reader. Get. String( 1 ) ); <script language = "JScript" runat = "server"> // close database connection function Page_Load( sender : Object, events : Event. Args ) data. Base. Connection. Close(); { } if ( !Is. Post. Back ) else { var data. Base. Connection : Ole. Db. Connection = data. Grid. Data. Source = Get. Data(); new data. Grid. Data. Bind(); Ole. Db. Connection( } Configuration. Settings. App. Settings( } // end Page_Load "Connection. String" ) ); var query. String : System. String = "SELECT last. Name, first. Name FROM Authors"; data. Base. Connection. Open(); var data. Base. Command : Ole. Db. Command = new Ole. Db. Command( query. String,

 // Read a database and return the Data. View </script> function Get. Data()

// Read a database and return the Data. View </script> function Get. Data() : ICollection { <form runat = "server"> var set : Data. Set = new Data. Set(); <Header: Image. Header id = "head" runat = "server"> // establish a connection, and query the database </Header: Image. Header> var data. Base. Connection: Ole. Db. Connection = new <br /> Ole. Db. Connection( Configuration. Settings. App. Settings( "Connection. String" ) ); Authors: <asp: Drop. Down. List id = "name. List" runat = "server" var author. ID : int = name. List. Selected. Index + 1; Width = "158 px" Height = "22 px"> </asp: Drop. Down. List> var query. String : String = <asp: button id = "button" text = "select" runat = "server"> "SELECT Titles. Title, Titles. ISBN, " + </asp: button> "Publishers. Publisher. Name FROM Author. ISBN " + <p> "INNER JOIN Titles ON Author. ISBN = " + <asp: Data. Grid id = "data. Grid" runat = "server"> "Titles. ISBN, Publishers WHERE " + </asp: Data. Grid> "(Author. ISBN. Author. ID = " + author. ID + ")"; </p> var data. Base. Command : Ole. Db. Command = </form> new Ole. Db. Command( query. String, data. Base. Connection </body> ); </html> var data. Adapter : Ole. Db. Data. Adapter = new Ole. Db. Data. Adapter( data. Base. Command ); data. Adapter. Fill( set ); // close database connection data. Base. Command. Connection. Close(); var data. View : Data. View = new Data. View( set. Tables[ 0 ] ); data. View. Sort = "Title"; return data. View; } // end Get. Data

How ASPs work Active Server Pages Processed by scripting engine Server-side Active. X control.

How ASPs work Active Server Pages Processed by scripting engine Server-side Active. X control. asp file extension Can contain XHTML tags Scripting written with VBScript Java. Script also used Others (Independent Software Vendors)

How ASPs work (cont’d) Active Server Pages Communication with Server Client HTTP request to

How ASPs work (cont’d) Active Server Pages Communication with Server Client HTTP request to server Active server page processes request and returns results ASP document is loaded into memory asp. dll scripting engine on server Parses (top to bottom)

Sequence Control Between Statements Alternation two sequences of statements may form alternatives so that

Sequence Control Between Statements Alternation two sequences of statements may form alternatives so that only one or other sequence is executed. Iteration a sequence of statements may be executed repeatedly. (zero or more times)

Conditional Statements If. . Then. . . Else The If. . Then. . .

Conditional Statements If. . Then. . . Else The If. . Then. . . Else instructions sequence is very similar to the one we may find in different kind of scripting languages. Let's check an example <% AA="water" If AA="water" Then response. write ("I want to drink water") Else response. write ("I want to drink milk") End If %>

Conditional Statements We may use it this way: • • • <% AA="water" If

Conditional Statements We may use it this way: • • • <% AA="water" If AA="water" Then %> I want to drink water <% Else %> I want to drink milk <% End If %> In both cases we have checked a condition (AA="water") and we have get a positive instruction (to write the sentence "I want to drink water"). We are allowed to execute any kind of instructions (including If. . then. . Else) and as many instructions as we want.

Iteration Statements For. . Next This instructions is also similar in different programming languages.

Iteration Statements For. . Next This instructions is also similar in different programming languages. Typical example: I want to say "Hello" 10 times<BR> <% For mynumber = 1 to 10 %> <% =mynumber %> Hello<BR> <% Next %> END In this case we have defined a variable ("mynumber") and using the For. . . Next instruction we have repeated 10 times line 4. Similarly to If. . Then. . Else instruction, we are allowed to execute any kind of instructions and as many of them as we want.

Iteration Statements Do While. . . Loop Again, we will define a condition and

Iteration Statements Do While. . . Loop Again, we will define a condition and one or more instructions: <% mynumber=0 Do While mynumber<10 response. write("Hello<HR>") mynumber=mynumber+1 Loop %> • In this example the condition is "mynumber<10" and the instructions defines a response text and an increment of the variable "mynumber". In the example, mynumber will be increased until it gets a value of 10. Then the loop will be abandon. Several instruction may be used within the loop.

Using Variables, and Forms in Active Server Pages Forms are a convenient way to

Using Variables, and Forms in Active Server Pages Forms are a convenient way to communicate with visitors to your Web site. Using forms, you can create a survey form and ask visitors to fill it out. When they fill out the form, you can process the results automatically. There are two steps: first you create the form, and then you process it To create a form for an Active Server Page, just create a standard HTML form

Using Variables, and Forms in Active Server Pages provide a mechanism for processing forms

Using Variables, and Forms in Active Server Pages provide a mechanism for processing forms Unlike CGI scripting, doesn't involve serious programming: the Request. Form.

Using Variables To do more with your forms than display their contents in a

Using Variables To do more with your forms than display their contents in a Web page. For example, based on the contents of the form, you may want to create a variable and insert that variable in different places of your response page. Thus you may need to create a variable. To do that, just make up a name and set it equal to the contents of the field. For example, if you have a field called "Cat. Name" in your form, you can save it into a variable called "The. Name" by typing: <% The. Name = Request. Form("Cat. Name") %>

Using Variables If you want to display "Visitor. Name" several times within a text

Using Variables If you want to display "Visitor. Name" several times within a text you only need to include the variable in the text. For example: My cat’s name is <% =The. Name %>. Do you want to see <% =The. Name %>? .

Cold. Fusion Macromedia --> Adobe Cold. Fusion Markup Language (CFML) Support XML, Cold. Fusion

Cold. Fusion Macromedia --> Adobe Cold. Fusion Markup Language (CFML) Support XML, Cold. Fusion Components (CFCs) and Web services. cfm extension --> Cold. Fusion template Cold. Fusion software includes: CFML interpreter and Cold. Fusion Administrator

<? xml version = "1. 0"? > <!DOCTYPE html PUBLIC "-//W 3 C//DTD XHTML

<? xml version = "1. 0"? > <!DOCTYPE html PUBLIC "-//W 3 C//DTD XHTML 1. 1//EN" "http: //www. w 3. org/TR/xhtml 11/DTD/xhtml 11. dtd"> yyyy" )#</cfoutput> </td> <td> <!--- Fig. 27. 1 : clock. cfm ---> <!--- A simple Cold. Fusion example ---> <!--- CFML comment tag ---> <!-- XHTML comment tag --> <html xmlns = "http: //www. w 3. org/1999/xhtml"> <head> <title>A Simple Cold. Fusion Example</title> <style type = "text/css"> p { font-size: 14 pt; color: blue } td { background-color: black; color: yellow } </style> </head> <body> <p>A Simple Cold. Fusion Example</p> <table border = "1"> <tr> <td> <!--- #’s between cfoutput tags are processed ---> <!--- Display the current date ---> <cfoutput>#date. Format( now(), "mmmm dd, <!--- Display the current time ---> <cfoutput>#time. Format( now(), "hh: mm: ss tt" )#</cfoutput> </td> </tr> <td colspan = "2"> <!--- Display the output of now() ---> <cfoutput>Date/Time: #now()#</cfoutput> </td> </tr> </table> </body> </html>

Variables and Expressions cfset <cfset first. Number = 1> <cfset second. Number = 4>

Variables and Expressions cfset <cfset first. Number = 1> <cfset second. Number = 4> <cfset added. Numbers = first. Number + second. Number> cfif = if <cfif NOT is. Defined (“url. name”)> cfelseif cfelse

<? xml version = "1. 0"? > <!DOCTYPE html PUBLIC "-//W 3 C//DTD XHTML

<? xml version = "1. 0"? > <!DOCTYPE html PUBLIC "-//W 3 C//DTD XHTML 1. 1//EN" "http: //www. w 3. org/TR/xhtml 11/DTD/xhtml 11. dtd"> <!--- Fig. 27. 9 : form_process. cfm ---> <!--- A simple auction bid processing form ---> <html xmlns = "http: //www. w 3. org/1999/xhtml"> <head> <title>Simple Auction</title> <style type = "text/css"> p { font-family: arial, sans-serif; font-size: 14 pt; color: navy } </style> </head> <body> <!--- Determine if bid. Price exists ---> <cfif is. Defined( "form. bid. Price" )> <!--- Determine if bid. Price is a number ---> <cfif is. Numeric( form. bid. Price )> <!--- Determine is bid. Price is GTE 0 ---> <cfif form. bid. Price GTE 0> <!--- Display bid from form field ---> <p> Your bid is: <cfoutput>$#form. bid. Price#</cfoutput> </p> <cfelse> <p>Your bid must be greater then or equal to $0. 00!</p> </cfif> <cfelse> <p>Your bid must be a valid numeric dollar amount!</p> </cfif> <cfelse> <p>Error, no bid found. </p> </cfif> </body> </html>