Lecture 1-9 Definitions 1. A eb broser is a software application that enables a user to display and interact with text, images, videos, music and other information typically located on a Web page at a website on the World Wide Web or a local area network. Text and images on a Web page can contain hyperlinks to other Web pages at the same or different website. Web browsers allow a user to quickly and easily access information provided on many Web pages at many websites by traversing these links. Web browsers format T!" information for display, so the appearance of a Web page may differ between browsers. #ome of the Web browsers available for personal computers include $nternet %xplorer, !o&illa 'irefox, #afari, (pera, and )etscape *. A Web !age or eb!age is a resource of information that is suitable for the World Wide Web and can be accessed through a web browser. This information is usually in T!" or +T!" format, and may provide navigation to other web pages via hypertext links. Web pages may be retrieved from a local computer or from a remote web server. The web server may restrict access only to a private network, e.g. a corporate intranet, or it may publish pages on the World Wide Web. Web pages are requested and served from web servers using ypertext Transfer ,rotocol -TT,.. Web pages may consist of files of static text stored within the web server/s file system -static web pages., or the web server may construct the -+.T!" for each web page when it is requested by a browser -dynamic web pages.. 0lient1side scripting can make web pages more responsive to user input once in the client browser. A web page is a type of web document. "# Web site -alternatively, ebsite or eb site. is a collection of Web pages, images, videos or other digital assets that is hosted on one or several Web server-s., usually accessible via the $nternet, cell phone or a "A). A Web page is a document, typically written in T!", that is almost always accessible via TT,, a protocol that transfers information from the Web server to display in the user/s Web browser. All publicly accessible websites are seen collectively as constituting the 2World Wide Web2. The pages of websites can usually be accessed from a common root 34" called the homepage, and usually reside on the same physical server. The 34"s of the pages organi&e them into a hierarchy, although the hyperlinks between them control how the reader perceives the overall structure and how the traffic flows between the different parts of the sites. #ome websites require a subscription to access some or all of their content. %xamples of subscription sites include many business sites, parts of many news sites, academic 5ournal sites, gaming sites, message boards, Web1based e1mail, services, social networking website, and sites providing real1time stock market data. 6. $n computing, a !rotocol is a convention or standard that controls or enables the connection, communication, and data transfer between two computing endpoints. $n its simplest form, a protocol can be defined as the rules go$erning the syntax, semantics, and synchroni&ation of communication. ,rotocols may be implemented by hardware, software, or a combination of the two. At the lowest level, a protocol defines the behavior of a hardware connection. 7. A computer system that is accessed by a user working at a remote location. Typically, the term is used when there are two computer systems connected by modems and telephone lines. The system that contains the data is called the host, while the computer at which the user sits is called the remote terminal. (*. A computer that is connected to a T0,8$, network, including the $nternet. %ach host has a unique $, address. -9. To provide the infrastructure for a computer service. 'or example, there are many companies that host files, programs, applications or even a Web server for companies and individuals. $n the case of a Web server, it means that they provide the hardware, software, and communications lines required by the server, but the content on the server may be controlled by someone else. :. An IP a%%ress -Internet Protocol a%%ress. is a unique address that certain electronic devices currently use in order to identify and communicate with each other on a computer network utili&ing the $nternet ,rotocol standard -IP.;in simpler terms, a computer address. Any participating network device;including routers, switches, computers, infrastructure servers -e.g., )T,, <)#, <0,, #)!,, etc.., printers, $nternet fax machines, and some telephones;can have its own address that is unique within the scope of the specific network. #ome $, addresses are intended to be unique within the scope of the global $nternet, while others need to be unique only within the scope of an enterprise =. The Worl% Wi%e Web -commonly shortened to the Web. is a system of interlinked, hypertext documents accessed via the $nternet. With a web browser, a user views web pages that may contain text, images, videos, and other multimedia and navigates between them using hyperlinks. W&B S&'V&' The term web server can mean one of two things: 1. A computer program that is responsible for accepting TT, requests from clients, which are known as web browsers, and serving them TT, responses along with optional data contents, which usually are web pages such as T!" documents and linked ob5ects -images, etc... *. A computer that runs a computer program which provides the functionality described in the first sense of the term. Although web server programs differ in detail, they all share some basic common features. 1. (TTP > every web server program operates by accepting TT, requests from the client, and providing an TT, response to the client. The TT, response usually consists of an T!" document, but can also be a raw file, an image, or some other type of document -defined by !$!%1types.? if some error is found in client request or while trying to serve the request, a web server has to send an error response which may include some custom T!" or text messages to better explain the problem to end users. *. Logging > usually web servers have also the capability of logging some detailed information, about client requests and server responses, to log files? this allows the webmaster to collect statistics by running log analy&ers on log files. In practice many web servers implement the following features also: 1. Authentication , optional authori&ation request -request of user name and password. before allowing access to some or all kind of resources. *. andling of not only static content -file content recorded in server/s filesystem-s.. but of %)namic content too by supporting one or more related interfaces -##$, 0@$, #0@$, 'ast0@$, A#,, ,,, A#,, A#, .)%T, #erver A,$ such as )#A,$, $#A,$, etc... 9. (TTPS support -by ##" or T"#. to allow secure -encrypted. connections to the server on the standard port 669 instead of usual port BC. 6. *ontent com!ression -i.e. by g&ip encoding. to reduce the si&e of the responses -to lower bandwidth usage, etc... 7. Virtual hosting to serve many web sites using one $, address. :. Large file su!!ort to be able to serve files whose si&e is greater than * @D on 9* bit (#. Ban%i%th throttling to limit the speed of responses in order to not saturate the network and to be able to serve more clients. (TTP 'e+uest T)!es 'e+uest Metho%s HTTP defines eight methods (sometimes referred to as verbs! indicating the desired action to be performed on the identified resource. %A< Asks for the response identical to the one that would correspond to a @%T request, but without the response body. This is useful for retrieving meta1 information written in response headers, without having to transport the entire content. @%T 4equests a representation of the specified resource. Dy far the most common method used on the Web today. #hould not be used for operations that cause side1 effects -using it for actions in web applications is a common misuse.. #ee /safe methods/ below. ,(#T #ubmits data to be processed -e.g. from an T!" form. to the identified resource. The data is included in the body of the request. This may result in the creation of a new resource or the updates of existing resources or both. ,3T 3ploads a representation of the specified resource. <%"%T% <eletes the specified resource. T4A0% %choes back the received request, so that a client can see what intermediate servers are adding or changing in the request. (,T$()# 4eturns the TT, methods that the server supports. This can be used to check the functionality of a web server. 0())%0T 0onverts the request connection to a transparent T0,8$, tunnel, usually to facilitate ##"1encrypted communication -TT,#. through an unencrypted TT, proxy. E1F
Introduction to Microsoft IIS $$# :.C includes new features designed to help businesses, $T professionals, and Web administrators achieve their goals of performance, reliability, scalability, and security for potentially thousands of Web sites either on a single $$# server or on multiple servers. This section describes new and notable features in $$# :.C. 4eliability 'eatures> <escribes new modes of operation and World Wide Web ,ublishing #ervice -WWW service. processes. #ecurity 'eatures> <escribes new features designed to secure your Web sites, data, and your $$# server. ,erformance 'eatures> <escribes performance and scalability features. Web Application Technologies> <escribes the $$# :.C implementation of !icrosoftG A#,.)%T, A#,, and the A<#$ provider. Administrative Tools and 'eatures> <escribes metabase changes and new administrative tools. $nternet #tandards> <escribes support for Web and $nternet standard protocols. $nternet ,rotocol Hersion : 'eatures> <escribes the $$# :.C functionality that supports $nternet ,rotocol Hersion : -$pv:.. *reating Virtual Directories in IIS ,#- .IIS ,#-/ Virtual Directories A sub"directory of a web"site in II# can be either a physical sub"directory, or it can be a $irtual %irectory that is logically mapped to that location. It really should not matter whether the directory is a physical sub"directory or a $irtual %irectory, &ust li'e the location of the web"root isn(t e)posed. In most production cases, especially with shared web"hosts, you will only be able to create physical sub"directories, probably using *TP or similar tools. If you open up the Internet #ervices +anager in your Administrative Tools, also called II# +anager, and drill down you will see the logical structures. Physical directories are shown with a folder icon, while $irtual %irectories are shown with a special folder icon that has a globe as part of the icon. ,ou may also see another icon, either a bo) around a globe icon (-in ./01P! or a gear icon (-.223!, which indicates the directory is an II# Application. IIS Applications An II# Application is a directory, physical or virtual, that has been setup in a manner that ma'es it logically independent from the rest of the web"site. Its purpose is basically to ma'e sub"directories act &ust li'e real web"sites, which is very useful on -in ./01P Pro, but not really necessary on a #erver. Its important to understand that you cannot create an II# Application simply using *TP or similar tools "" and this is the cause of many A#P.45T problems. #o how do you create an II# Application6 *irst, $#.45T automatically ma'es all new web pro&ects into II# Applications, whether you want it to be or not. 7therwise, you need to use II# +anager to create or setup an II# Application, or get your web"host to do it for you (WebHost4Life.com has a tool for this!. The easiest techni8ue is to use II# +anager to create a new $irtual %irectory "" it will also be an II# Application by default, which adds to the confusion. $n most cases, the content you publish to your Web or 'T, site is located in a root or home directory on your computer, such as 0>I$netpubIWwwrootI. owever, there might be instances when the content is located somewhere else, or even on a remote computer. To publish from any directory not contained within your home or root directory, you can create a virtual directory. A virtual directory is a directory that is not contained in the home directory but appears to client browsers as though it were. Jou can create a virtual directory through $$# !anager or by using Windows %xplorer. To create a $irtual %irector) b) using IIS Manager 1. $n $$# !anager, expand the local computer, expand the Web Sites or 0TP Sites folder, right1click the site or folder within which you want to create the virtual directory, point to 1e, and then click Virtual Director). The Virtual Director) *reation Wi2ar% appears. *. 0lick 1e3t. 9. $n the Alias box, type a name for the virtual directory. -0hoose a short name that is easy to type because the user types this name.. 6. 0lick 1e3t. 7. $n the Path box, type or browse to the physical directory in which the virtual directory resides, and then click 1e3t. :. 3nder Allo the folloing !ermissions, select the check boxes for the access permissions you want to assign to your users, and then click 1e3t# To start IIS Manager 1. 'rom the Start menu, point to A%ministrati$e Tools, and then click Internet Information Ser$ices .IIS/ Manager. To start IIS Manager from the 'un %ialog bo3 1. 'rom the Start menu, click 'un. *. $n the 4!en box, type inetmgr, and click 45. Jou can also access $$# from the 0omputer !anagement window. Accessing $$# in this way does not give you the range of administration options offered by $$# !anager? however, it does offer quick access and limited management options for your Web sites. To start IIS Manager from the *om!uter Management in%o 1. 'rom the Start menu, right1click M) *om!uter, and click Manage. *. $n the console tree, expand the Ser$ices an% A!!lications node. 9. 0lick Internet Information Ser$ices. The names and states of your Web sites appear in the details pane. 6. $n the console tree, expand the Internet Information Ser$ices node and any subsequent Web site nodes to see a list of directories and virtual directories for that Web site. D(TML Technologies With <T!" a Web developer can control how to display and position T!" elements in a browser window. (TML 6#- With T!" 6.C all formatting can be moved out of the T!" document and into a separate st)le sheet. Decause T!" 6.C separates the presentation of the document from its structure, we have total control of presentation layout without messing up the document content. *asca%ing St)le Sheets .*SS/ With 0## we have a style and layout model for T!" documents. 0## was a breakthrough in Web design because it allowed developers to control the style and layout of multiple Web pages all at once. As a Web developer you can define a style for each T!" element and apply it to as many Web pages as you want. To make a global change, simply change the style, and all elements in the Web are updated automatically. The Document 4b7ect Mo%el .D4M/ D4M stands for the Document 4b5ect Model. The T!" <(! is the <ocument (b5ect !odel for T!". The T!" <(! defines a standard set of ob5ects for T!", and a standard way to access and manipulate T!" ob5ects. "The W3C Document Object Model (DOM) is a platform and language neutral interface that allows programs and scripts to dnamicall access and update the content! structure! and stle of a document". 8a$aScri!t Allows you to write code to control all T!" elements. 8a$aScri!t 0orm Vali%ation 8a$aScri!t can be use% to $ali%ate in!ut %ata in (TML forms before sen%ing off the content to a ser$er# 8a$aScri!t 0orm Vali%ation Aava#cript can be used to validate input data in T!" forms before sending off the content to a server. 'orm data that typically are checked by a Aava#cript could be> has the user left required fields emptyK has the user entered a valid e1mail addressK has the user entered a valid dateK has the user entered text in a numeric fieldK 'e+uire% 0iel%s The function below checks if a required field has been left empty. $f the required field is blank, an alert box alerts a message and the function returns false. $f a value is entered, the function returns true -means that data is (L.> function validateMrequired-field,alerttxt. N with -field. N if -valueOOnullPPvalueOO22. Nalert-alerttxt.?return falseQ else Nreturn trueQ Q Q The entire script, with the T!" form could look something like this> RhtmlS RheadS Rscript typeO2text85avascript2S function validateMrequired-field,alerttxt. N with -field. N if -valueOOnullPPvalueOO22. Nalert-alerttxt.?return falseQ else Nreturn trueQ Q Q function validateMform-thisform. N with -thisform. N if -validateMrequired-email,2%mail must be filled outT2.OOfalse. Nemail.focus-.?return falseQ Q Q R8scriptS R8headS RbodyS Rform actionO2submitpage.htm2 onsubmitO2return validateMform-this.2 methodO2post2S %mail> Rinput typeO2text2 nameO2email2 si&eO29C2S Rinput typeO2submit2 valueO2#ubmit2S R8formS R8bodyS R8htmlS &-mail Vali%ation The function below checks if the content has the general syntax of an email. This means that the input data must contain at least an U sign and a dot -... Also, the U must not be the first character of the email address, and the last dot must at least be one character after the U sign> function validateMemail-field,alerttxt. N with -field. N aposOvalue.index(f-2U2. dotposOvalue.last$ndex(f-2.2. if -aposR1PPdotpos1aposR*. Nalert-alerttxt.?return falseQ else Nreturn trueQ Q Q The entire script, with the T!" form could look something like this> RhtmlS RheadS Rscript typeO2text85avascript2S function validateMemail-field,alerttxt. N with -field. N aposOvalue.index(f-2U2. dotposOvalue.last$ndex(f-2.2. if -aposR1PPdotpos1aposR*. Nalert-alerttxt.?return falseQ else Nreturn trueQ Q Q function validateMform-thisform. N with -thisform. N if -validateMemail-email,2)ot a valid e1mail addressT2.OOfalse. Nemail.focus-.?return falseQ Q Q R8scriptS R8headS RbodyS Rform actionO2submitpage.htm2 onsubmitO2return validateMform-this.?2 methodO2post2S %mail> Rinput typeO2text2 nameO2email2 si&eO29C2S Rinput typeO2submit2 valueO2#ubmit2S R8formS R8bodyS R8htmlS What is *SS9 *SS stands for *ascading Style Sheets #tyles define ho to %is!la) T!" elements #tyles are normally stored in St)le Sheets #tyles were added to T!" 6.C to sol$e a !roblem &3ternal St)le Sheets can save you a lot of work %xternal #tyle #heets are stored in *SS files *SS S)nta3 S)nta3 The 0## syntax is made up of three parts> a selector, a property and a value> selector Nproperty> valueQ The selector is normally the T!" element8tag you wish to define, the property is the attribute you wish to change, and each property can take a value. The property and value are separated by a colon, and surrounded by curly braces> body Ncolor> blackQ 1ote: $f the value is multiple words, put quotes around the value> p Nfont1family> 2sans serif2Q 1ote: $f you wish to specify more than one property, you must separate each property with a semicolon. The example below shows how to define a center aligned paragraph, with a red text color> p Ntext1align>center?color>redQ To make the style definitions more readable, you can describe one property on each line, like this> p N text1align> center? color> black? font1family> arial Q ;rou!ing Jou can group selectors. #eparate each selector with a comma. $n the example below we have grouped all the header elements. All header elements will be displayed in green text color> h1,h*,h9,h6,h7,h: N color> green Q The class Selector With the class selector you can define different styles for the same type of T!" element. #ay that you would like to have two types of paragraphs in your document> one right1 aligned paragraph, and one center1aligned paragraph. ere is how you can do it with styles> p.right Ntext1align> rightQ p.center Ntext1align> centerQ Jou have to use the class attribute in your T!" document> Rp classO2right2S This paragraph will be right1aligned. R8pS Rp classO2center2S This paragraph will be center1aligned. R8pS 1ote: To apply more than one class per given element, the syntax is> Rp classO2center bold2S This is a paragraph. R8pS The paragraph above will be styled by the class 2center2 A)< the class 2bold2. Jou can also omit the tag name in the selector to define a style that will be used by all T!" elements that have a certain class. $n the example below, all T!" elements with classO2center2 will be center1aligned> .center Ntext1align> centerQ $n the code below both the h1 element and the p element have classO2center2. This means that both elements will follow the rules in the 2.center2 selector> Rh1 classO2center2S This heading will be center1aligned R8h1S Rp classO2center2S This paragraph will also be center1aligned. R8pS A%% St)les to &lements ith Particular Attributes Jou can also apply styles to T!" elements with particular attributes. The style rule below will match all input elements that has a type attribute with a value of 2text2> $nputEtypeO2text2F Nbackground1color> blueQ The i% Selector Jou can also define styles for T!" elements with the id selector. The id selector is defined as a V. The style rule below will match the element that has an id attribute with a value of 2green2> Vgreen Ncolor> greenQ The style rule below will match the p element that has an id with a value of 2para12> pVpara1 N text1align> center? color> red Q *SS *omments 0omments are used to explain your code, and may help you when you edit the source code at a later date. Drowsers will ignore a comment. A 0## comment begins with 28W2, and ends with 2W82, like this> 8W This is a comment W8 p N text1align> center? 8W This is another comment W8 color> black? font1family> arial Q (o to Insert a St)le Sheet When a browser reads a style sheet, it will format the document according to it. There are three ways of inserting a style sheet> &3ternal St)le Sheet An external style sheet is ideal when the style is applied to many pages. With an external style sheet, you can change the look of an entire Web site by changing one file. %ach page must link to the style sheet using the RlinkS tag. The RlinkS tag goes inside the head section> RheadS Rlink relO2stylesheet2 typeO2text8css2 hrefO2mystyle.css2 8S R8headS The browser will read the style definitions from the file mystyle.css, and format the document according to it. An external style sheet can be written in any text editor. The file should not contain any html tags. Jour style sheet should be saved with a .css extension. An example of a style sheet file is shown below> hr Ncolor> siennaQ p Nmargin1left> *CpxQ body Nbackground1image> url-2images8back6C.gif2.Q Internal St)le Sheet An internal style sheet should be used when a single document has a unique style. Jou define internal styles in the head section by using the RstyleS tag, like this> RheadS Rstyle typeO2text8css2S hr Ncolor> siennaQ p Nmargin1left> *CpxQ body Nbackground1image> url-2images8back6C.gif2.Q R8styleS R8headS The browser will now read the style definitions, and format the document according to it. Inline St)les An inline style loses many of the advantages of style sheets by mixing content with presentation. 3se this method sparingly, such as when a style is to be applied to a single occurrence of an element. To use inline styles you use the style attribute in the relevant tag. The style attribute can contain any 0## property. The example shows how to change the color and the left margin of a paragraph> Rp styleO2color> sienna? margin1left> *Cpx2S This is a paragraph R8pS Multi!le St)le Sheets $f some properties have been set for the same selector in different style sheets, the values will be inherited from the more specific style sheet. 'or example, an external style sheet has these properties for the h9 selector> h9 N color> red? text1align> left? font1si&e> Bpt Q And an internal style sheet has these properties for the h9 selector> h9 N text1align> right? font1si&e> *Cpt Q $f the page with the internal style sheet also links to the external style sheet the properties for h9 will be> color> red? text1align> right? font1si&e> *Cpt The color is inherited from the external style sheet and the text1alignment and the font1 si&e is replaced by the internal style sheet. Lecture 1--<= Acti$e Ser$er Pages> Working with A#, ,ages, A#, (b5ects, 'ile #ystem (b5ects, #ession Tracking and 0ookies, Active+ <ata (b5ects, Accessing a <atabase from Active #erver ,age. Wor>ing ith ASP Pages An A#, file can contain text, T!" tags and scripts. #cripts in an A#, file are executed on the server. What is ASP9 A#, stands for Active Server Pages A#, is a program that runs inside IIS $$# stands for Internet Information Services $$# comes as a free component with Win%os <--- $$# is also a part of the Win%os 1T 6#- 4!tion Pac> The (ption ,ack can be %onloa%e% from !icrosoft PWS is a smaller 1 but fully functional 1 version of $$# ,W# can be found on your Win%os 9?@9A *D What is an ASP 0ile9 An A#, file is 5ust the same as an T!" file An A#, file can contain text, T!", +!", and scripts #cripts in an A#, file are executed on the server An A#, file has the file extension 2.asp2 What can ASP %o for )ou9 <ynamically edit, change or add any content of a Web page 4espond to user queries or data submitted from T!" forms Access any data or databases and return the results to a browser 0ustomi&e a Web page to make it more useful for individual users The advantages of using A#, instead of 0@$ and ,erl, are those of simplicity and speed ,rovide security since your A#, code can not be viewed from the browser 0lever A#, programming can minimi&e the network traffic (o to rite some te3t ith ASP# A#, #ource> BhtmlC Bbo%)C BD res!onse#rite.E(ello Worl%FE/ DC B@bo%)C B@htmlC (utput 4esult (ello Worl%F ow to format the text with T!" tags. ASP Source: RhtmlS RbodyS RX response.write-2Rh*SJou can use T!" tags to format the textTR8h*S2. XS RX response.write-2Rp styleO/color>VCCCCff/SThis text is styled with the style attributeT R8pS2. XS R8bodyS R8htmlS 4ut!ut 'esult: Gou can use (TML tags to format the te3tF This text is styled with the style attributeT The Dasic #yntax 4ule An A#, file normally contains T!" tags, 5ust like an T!" file. owever, an A#, file can also contain ser$er scri!ts, surrounded by the delimiters BD and DC. #erver scripts are e3ecute% on the ser$erH and can contain any expressions, statements, procedures, or operators valid for the scripting language you prefer to use. Write 4ut!ut to a Broser The response.write command is used to write output to a browser. The following example sends the text 2ello World2 to the browser> RhtmlS RbodyS RX response.write-2ello WorldT2. XS R8bodyS R8htmlS There is also a shorthand method for the response.write command. The following example also sends the text 2ello World2 to the browser> RhtmlS RbodyS RXO2ello WorldT2XS R8bodyS R8htmlS VBScri!t Jou can use several scripting languages in A#,. owever, the default scripting language is HD#cript> RhtmlS RbodyS RX response.write-2ello WorldT2. XS R8bodyS R8htmlS The example above writes 2ello WorldT2 into the body of the document. 8a$aScri!t To set Aava#cript as the default scripting language for a particular page you must insert a language specification at the top of the page> RXU languageO25avascript2XS RhtmlS RbodyS RX 4esponse.Write-2ello WorldT2. XS R8bodyS R8htmlS A#, Hariables A $ariable is use% to store information# If the $ariable is %eclare% outsi%e a !roce%ure it can be change% b) an) scri!t in the ASP file# If the $ariable is %eclare% insi%e a !roce%ureH it is create% an% %estro)e% e$er) time the !roce%ure is e3ecute%# <eclare a variable Hariables are used to store information. This example demonstrates how to declare a variable, assign a value to it, and use the value in a text. ASP Source: RhtmlS RbodyS RX dim name nameO2<onald <uck2 response.write-2!y name is> 2 Y name. XS R8bodyS R8htmlS 4ut!ut 'esult: !y name is> <onald <uck Lifetime of Variables A variable declared outside a procedure can be accessed and changed by any script in the A#, file. A variable declared inside a procedure is created and destroyed every time the procedure is executed. )o scripts outside the procedure can access or change the variable. To declare variables accessible to more than one A#, file, declare them as session variables or application variables. Session Variables #ession variables are used to store information about ()% single user, and are available to all pages in one application. Typically information stored in session variables are name, id, and preferences. A!!lication Variables Application variables are also available to all pages in one application. Application variables are used to store information about A"" users in a specific application. <eclare an array Arrays are used to store a series of related data items. This example demonstrates how to declare an array that stores names. ASP Source: RhtmlS RbodyS RX <im famname-:.,i famname-1. O 2Aan %gil2 famname-*. O 2Tove2 famname-9. O 2ege2 famname-6. O 2#tale2 famname-7. O 2Lai Aim2 famname-:. O 2Dorge2 'or i O 1 to : response.write-famname-i. Y 2Rbr 8S2. )ext XS R8bodyS R8htmlS 4ut!ut 'esult: Aan %gil Tove ege #tale Lai Aim Dorge Loo! through the (TML hea%ers ow to loop through the six headers in T!". ASP Source: RhtmlS RbodyS RX dim i for iO1 to : response.write-2Rh2 Y i Y 2Seader 2 Y i Y 2R8h2 Y i Y 2S2. next XS R8bodyS R8htmlS 4ut!ut 'esult: (ea%er 1 (ea%er < (ea%er " (ea%er 6 (ea%er ? (ea%er , &3am!les 0all a procedure using HD#cript ow to call a HD#cript procedure from A#,. ASP Source: RhtmlS RheadS RX sub vbproc-num1,num*. response.write-num1Wnum*. end sub XS R8headS RbodyS RpS Jou can call a procedure like this> R8pS RpS 4esult> RXcall vbproc-9,6.XS R8pS RpS (r, like this> R8pS RpS 4esult> RXvbproc 9,6XS R8pS R8bodyS R8htmlS 4ut!ut 'esult: Jou can call a procedure like this> 4esult> 1* (r, like this> 4esult> 1* *all a !roce%ure using 8a$aScri!t ow to call a Aava#cript procedure from A#,. ASP Source: RXU languageO25avascript2 XS RhtmlS RheadS RX function 5sproc-num1,num*. N 4esponse.Write-num1Wnum*. Q XS R8headS RbodyS RpS 4esult> RX5sproc-9,6.XS R8pS R8bodyS R8htmlS 4ut!ut 'esult: 4esult> 1* *all !roce%ures using VBScri!t ow to call both a Aava#cript procedure and a HD#cript procedure in an A#, file. ASP Source: RhtmlS RheadS RX sub vbproc-num1,num*. 4esponse.Write-num1Wnum*. end sub XS Rscript languageO25avascript2 runatO2server2S function 5sproc-num1,num*. N 4esponse.Write-num1Wnum*. Q R8scriptS R8headS RbodyS RpS4esult> RXcall vbproc-9,6.XSR8pS RpS4esult> RXcall 5sproc-9,6.XSR8pS R8bodyS R8htmlS 4ut!ut 'esult: 4esult> 1* 4esult> 1* Proce%ures The A#, source code can contain procedures and functions> RhtmlS RheadS RX sub vbproc-num1,num*. response.write-num1Wnum*. end sub XS R8headS RbodyS RpS4esult> RXcall vbproc-9,6.XSR8pS R8bodyS R8htmlS $nsert the RXU languageO2language2 XS line above the RhtmlS tag to write procedures or functions in another scripting language than default> RXU languageO25avascript2 XS RhtmlS RheadS RX function 5sproc-num1,num*. N 4esponse.Write-num1Wnum*. Q XS R8headS RbodyS RpS4esult> RX5sproc-9,6.XSR8pS R8bodyS R8htmlS ASP 0orms an% Iser In!ut The 'e+uest#Juer)String an% 'e+uest#0orm comman%s ma) be use% to retrie$e information from formsH li>e user in!ut# &3am!les A form with methodO2get2 ow to interact with the user, with the 4equest.Zuery#tring command. ASP Source: RhtmlS RbodyS Rform actionO2demoMreqquery.asp2 methodO2get2S Jour name> Rinput typeO2text2 nameO2fname2 si&eO2*C2 8S Rinput typeO2submit2 valueO2#ubmit2 8S R8formS RX dim fname fnameO4equest.Zuery#tring-2fname2. $f fnameRS22 Then 4esponse.Write-2ello 2 Y fname Y 2TRbr 8S2. 4esponse.Write-2ow are you todayK2. %nd $f XS R8bodyS R8htmlS 4ut!ut 'esult: Jour name> Submit A form with methodO2post2 ow to interact with the user, with the 4equest.'orm command. ASP Source: RhtmlS RbodyS Rform actionO2demoMsimpleform.asp2 methodO2post2S Jour name> Rinput typeO2text2 nameO2fname2 si&eO2*C2 8S Rinput typeO2submit2 valueO2#ubmit2 8S R8formS RX dim fname fnameO4equest.'orm-2fname2. $f fnameRS22 Then 4esponse.Write-2ello 2 Y fname Y 2TRbr 8S2. 4esponse.Write-2ow are you todayK2. %nd $f XS R8bodyS R8htmlS 4ut!ut 'esult: Jour name> Submit A form ith ra%io buttons ow to interact with the user, through radio buttons, with the 4equest.'orm command. ASP Source: RhtmlS RX dim cars carsO4equest.'orm-2cars2. XS RbodyS Rform actionO2demoMradiob.asp2 methodO2post2S RpS,lease select your favorite car>R8pS Rinput typeO2radio2 nameO2cars2 RXif carsO2Holvo2 then 4esponse.Write-2checked2.XS valueO2Holvo2SHolvoR8inputS Rbr 8S Rinput typeO2radio2 nameO2cars2 RXif carsO2#aab2 then 4esponse.Write-2checked2.XS valueO2#aab2S#aabR8inputS Rbr 8S Rinput typeO2radio2 nameO2cars2 RXif carsO2D!W2 then 4esponse.Write-2checked2.XS valueO2D!W2SD!WR8inputS Rbr 8SRbr 8S Rinput typeO2submit2 valueO2#ubmit2 8S R8formS RX if carsRS22 then 4esponse.Write-2RpSJour favorite car is> 2 Y cars Y 2R8pS2. end if XS R8bodyS R8htmlS 4ut!ut 'esult: ,lease select your favorite car> Holvo #aab D!W Submit Iser In!ut The 4equest ob5ect may be used to retrieve user information from forms. 0orm e3am!le: Rform methodO2get2 actionO2simpleform.asp2S 'irst )ame> Rinput typeO2text2 nameO2fname2 8S Rbr 8S "ast )ame> Rinput typeO2text2 nameO2lname2 8S Rbr 8SRbr 8S Rinput typeO2submit2 valueO2#ubmit2 8S R8formS 3ser input can be retrieved in two ways> With 4equest.Zuery#tring or 4equest.'orm. 'e+uest#Juer)String The 4equest.Zuery#tring command is used to collect values in a form with methodO2get2. $nformation sent from a form with the @%T method is visible to everyone -it will be displayed in the browser/s address bar. and has limits on the amount of information to send. $f a user typed 2Dill2 and 2@ates2 in the form example above, the 34" sent to the server would look like this> http>88www.w9schools.com8simpleform.aspKfnameODillYlnameO@ates Assume that the A#, file 2simpleform.asp2 contains the following script> RbodyS Welcome RX response.write-request.querystring-2fname2.. response.write-2 2 Y request.querystring-2lname2.. XS R8bodyS The browser will display the following in the body of the document> Welcome Dill @ates 'e+uest#0orm The 4equest.'orm command is used to collect values in a form with methodO2post2. $nformation sent from a form with the ,(#T method is invisible to others and has no limits on the amount of information to send. $f a user typed 2Dill2 and 2@ates2 in the form example above, the 34" sent to the server would look like this> http>88www.w9schools.com8simpleform.asp Assume that the A#, file 2simpleform.asp2 contains the following script> RbodyS Welcome RX response.write-request.form-2fname2.. response.write-2 2 Y request.form-2lname2.. XS R8bodyS The browser will display the following in the body of the document> Welcome Dill @ates ASP 4b7ectsH 0ile S)stem 4b7ectsH Session Trac>ing an% *oo>ies ASP *oo>ies A coo>ie is often use% to i%entif) a user# &3am!les Welcome cookie ow to create a Welcome cookie. ASP Source: RX dim numvisits response.cookies-2)umHisits2..%xpiresOdate[9:7 numvisitsOrequest.cookies-2)umHisits2. if numvisitsO22 then response.cookies-2)umHisits2.O1 response.write-2WelcomeT This is the first time you are visiting this Web page.2. else response.cookies-2)umHisits2.Onumvisits[1 response.write-2Jou have visited this 2. response.write-2Web page 2 Y numvisits. if numvisitsO1 then response.write 2 time beforeT2 else response.write 2 times beforeT2 end if end if XS RhtmlS RbodyS R8bodyS R8htmlS 4ut!ut 'esult: WelcomeT This is the first time you are visiting this Web page. What is a *oo>ie9 A cookie is often used to identify a user. A cookie is a small file that the server embeds on the user/s computer. %ach time the same computer requests a page with a browser, it will send the cookie too. With A#,, you can both create and retrieve cookie values. (o to *reate a *oo>ie9 The 24esponse.0ookies2 command is used to create cookies. 1ote: The 4esponse.0ookies command must appear D%'(4% the RhtmlS tag. $n the example below, we will create a cookie named 2firstname2 and assign the value 2Alex2 to it> RX 4esponse.0ookies-2firstname2.O2Alex2 XS $t is also possible to assign properties to a cookie, like setting a date when the cookie should expire> RX 4esponse.0ookies-2firstname2.O2Alex2 4esponse.0ookies-2firstname2..%xpiresOV!ay 1C,*CC*V XS (o to 'etrie$e a *oo>ie Value9 The 24equest.0ookies2 command is used to retrieve a cookie value. $n the example below, we retrieve the value of the cookie named 2firstname2 and display it on a page> RX fnameO4equest.0ookies-2firstname2. response.write-2'irstnameO2 Y fname. XS 4ut!ut: 'irstnameOAlex A *oo>ie ith 5e)s $f a cookie contains a collection of multiple values, we say that the cookie has Leys. $n the example below, we will create a cookie collection named 2user2. The 2user2 cookie has Leys that contains information about a user> RX 4esponse.0ookies-2user2.-2firstname2.O2Aohn2 4esponse.0ookies-2user2.-2lastname2.O2#mith2 4esponse.0ookies-2user2.-2country2.O2)orway2 4esponse.0ookies-2user2.-2age2.O2*72 XS 'ea% all *oo>ies "ook at the following code> RX 4esponse.0ookies-2firstname2.O2Alex2 4esponse.0ookies-2user2.-2firstname2.O2Aohn2 4esponse.0ookies-2user2.-2lastname2.O2#mith2 4esponse.0ookies-2user2.-2country2.O2)orway2 4esponse.0ookies-2user2.-2age2.O2*72 XS Assume that your server has sent all the cookies above to a user. )ow we want to read all the cookies sent to a user. The example below shows how to do it -note that the code below checks if a cookie has Leys with the asLeys property.> RhtmlS RbodyS RX dim x,y for each x in 4equest.0ookies response.write-2RpS2. if 4equest.0ookies-x..asLeys then for each y in 4equest.0ookies-x. response.write-x Y 2>2 Y y Y 2O2 Y 4equest.0ookies-x.-y.. response.write-2Rbr 8S2. next else 4esponse.Write-x Y 2O2 Y 4equest.0ookies-x. Y 2Rbr 8S2. end if response.write 2R8pS2 next XS R8bodyS R8htmlS 4ut!ut: firstnameOAlex user>firstnameOAohn user>lastnameO#mith user>countryO)orway user>ageO*7 ASP Session 4b7ect The Session ob7ect is use% to store information aboutH or change settings for a user session# Variables store% in the Session ob7ect hol% information about one single userH an% are a$ailable to all !ages in one a!!lication# The #ession ob5ect When you are working with an application, you open it, do some changes and then you close it. This is much like a #ession. The computer knows who you are. $t knows when you start the application and when you end. Dut on the internet there is one problem> the web server does not know who you are and what you do because the TT, address doesn/t maintain state. A#, solves this problem by creating a unique cookie for each user. The cookie is sent to the client and it contains information that identifies the user. This interface is called the #ession ob5ect. The #ession ob5ect is used to store information about, or change settings for a user session. Hariables stored in the #ession ob5ect hold information about one single user, and are available to all pages in one application. 0ommon information stored in session variables are name, id, and preferences. The server creates a new #ession ob5ect for each new user, and destroys the #ession ob5ect when the session expires. When %oes a Session Start9 A session starts when> A new user requests an A#, file, and the @lobal.asa file includes a #essionM(n#tart procedure A value is stored in a #ession variable A user requests an A#, file, and the @lobal.asa file uses the Rob5ectS tag to instantiate an ob5ect with session scope When %oes a Session &n%9 A session ends if a user has not requested or refreshed a page in the application for a specified period. Dy default, this is *C minutes. $f you want to set a timeout interval that is shorter or longer than the default, you can set the Timeout property. The example below sets a timeout interval of 7 minutes> RX #ession.TimeoutO7 XS To end a session immediately, you may use the Aban%on method> RX #ession.Abandon XS 1ote: The main problem with sessions is W%) they should end. We do not know if the user/s last request was the final one or not. #o we do not know how long we should keep the session 2alive2. Waiting too long for an idle session uses up resources on the server, but if the session is deleted too soon the user has to start all over again because the server has deleted all the information. 'inding the right timeout interval can be difficultT Ti!: $f you are using session variables, store #!A"" amounts of data in them. Store an% 'etrie$e Session Variables The most important thing about the #ession ob5ect is that you can store variables in it. The example below will set the #ession variable username to 2<onald <uck2 and the #ession variable age to 27C2> RX #ession-2username2.O2<onald <uck2 #ession-2age2.O7C XS When the value is stored in a session variable it can be reached from A)J page in the A#, application> Welcome RX4esponse.Write-#ession-2username2..XS The line above returns> 2Welcome <onald <uck2. Jou can also store user preferences in the #ession ob5ect, and then access that preference to choose what page to return to the user. The example below specifies a text1only version of the page if the user has a low screen resolution> RX$f #ession-2screenres2.O2low2 ThenXS This is the text version of the page RX%lseXS This is the multimedia version of the page RX%nd $fXS 'emo$e Session Variables The 0ontents collection contains all session variables. $t is possible to remove a session variable with the 4emove method. The example below removes the session variable 2sale2 if the value of the session variable 2age2 is lower than 1B> RX $f #ession.0ontents-2age2.R1B then #ession.0ontents.4emove-2sale2. %nd $f XS To remove all variables in a session, use the 4emoveAll method> RX #ession.0ontents.4emoveAll-. XS Loo! Through the *ontents *ollection The 0ontents collection contains all session variables. Jou can loop through the 0ontents collection, to see what/s stored in it> RX #ession-2username2.O2<onald <uck2 #ession-2age2.O7C dim i 'or %ach i in #ession.0ontents 4esponse.Write-i Y 2Rbr 8S2. )ext XS 4esult> username age $f you do not know the number of items in the 0ontents collection, you can use the 0ount property> RX dim i dim 5 5O#ession.0ontents.0ount 4esponse.Write-2#ession variables> 2 Y 5. 'or iO1 to 5 4esponse.Write-#ession.0ontents-i. Y 2Rbr 8S2. )ext XS 4esult> #ession variables> * <onald <uck 7C Loo! Through the Static4b7ects *ollection Jou can loop through the #tatic(b5ects collection, to see the values of all ob5ects stored in the #ession ob5ect> RX dim i 'or %ach i in #ession.#tatic(b5ects 4esponse.Write-i Y 2Rbr 8S2. )ext XS ASP A!!lication 4b7ect A grou! of ASP files that or> together to !erform some !ur!ose is calle% an a!!lication# The A!!lication ob7ect in ASP is use% to tie these files together# A!!lication 4b7ect An application on the Web may be a group of A#, files. The A#, files work together to perform some purpose. The Application ob5ect in A#, is used to tie these files together. The Application ob5ect is used to store and access variables from any page, 5ust like the #ession ob5ect. The difference is that A"" users share one Application ob5ect, while with #essions there is one #ession ob5ect for %A0 user. The Application ob5ect should hold information that will be used by many pages in the application -like database connection information.. This means that you can access the information from any page. $t also means that you can change the information in one place and the changes will automatically be reflected on all pages. Store an% 'etrie$e A!!lication Variables Application variables can be accessed and changed by any page in the application. Jou can create Application variables in 2@lobal.asa2 like this> Rscript languageO2vbscript2 runatO2server2S #ub ApplicationM(n#tart application-2vartime2.O22 application-2users2.O1 %nd #ub R8scriptS $n the example above we have created two Application variables> 2vartime2 and 2users2. Jou can access the value of an Application variable like this> There are RX 4esponse.Write-Application-2users2.. XS active connections. A#, 4esponse (b5ect The ASP 'es!onse ob7ect is use% to sen% out!ut to the user from the ser$er# The A#, 4esponse ob5ect is used to send output to the user from the server. $t has collections, properties, and methods. !ethods like Metho% Descri!tion 4edirect 4edirects the user to a different 34" Write Writes a specified string to the output ASP 'e+uest 4b7ect The ASP 'e+uest ob7ect is use% to get information from the user# When a browser asks for a page from a server, it is called a request. The A#, 4equest ob5ect is used to get information from the user. $ts collections, properties, and methods are described below> Juer)String *ollection &3am!les A#, #ource> BhtmlC Bbo%)C Bform actionKE%emoLre++uer)#as!E metho%KEgetEC Gour name: Bin!ut t)!eKEte3tE nameKEfnameE si2eKE<-E @C Bin!ut t)!eKEsubmitE $alueKESubmitE @C B@formC BD %im fname fnameK'e+uest#Juer)String.EfnameE/ If fnameBCEE Then 'es!onse#Write.E(ello E M fname M EFBbr @CE/ 'es!onse#Write.E(o are )ou to%a)9E/ &n% If DC B@bo%)C B@htmlC (utput 4esult> Jour name> Submit A#, #ource BhtmlC Bbo%)C Bform actionKE%emoLsim!lere++uer)#as!E metho%KEgetEC 0irst name: Bin!ut t)!eKEte3tE nameKEfnameECBbrC Last name: Bin!ut t)!eKEte3tE nameKElnameECBbrC Bin!ut t)!eKEsubmitE $alueKESubmitEC B@formC BD 'es!onse#Write.'e+uest#Juer)String/ DC B@bo%)C B@htmlC (utput 4esult> 'irst name> "ast name> Submit 0orm *ollection &3am!les This e3am!le %emonstrates ho the 'orm collection retrie$es the $alues from a form# The form uses the P4ST metho%H hich means that the information sent is in$isible to othersH an% it has no limits .)ou can sen% a large amount of information/# BhtmlC Bbo%)C Bform actionKE%emoLsim!leform1#as!E metho%KE!ostEC 0irst name: Bin!ut t)!eKEte3tE nameKEfnameE $alueKEDonal%E @C Bbr @C Last name: Bin!ut t)!eKEte3tE nameKElnameE $alueKEDuc>E @C Bbr @C Bin!ut t)!eKEsubmitE $alueKESubmitE @C B@formC BD 'es!onse#Write.'e+uest#0orm/ DC B@bo%)C B@htmlC (utput 4esult> 'irst name> "ast name> Submit fnameKDonal%MlnameKDuc> This e3am!le %emonstrates ho to use the $alues retrie$e% from a form# We use the 'orm collection# The form uses the !ost metho%# A#, #ource> BhtmlC Bbo%)C Bform actionKE%emoLsim!leform#as!E metho%KE!ostEC Gour name: Bin!ut t)!eKEte3tE nameKEfnameE si2eKE<-E @C Bin!ut t)!eKEsubmitE $alueKESubmitE @C B@formC BD %im fname fnameK'e+uest#0orm.EfnameE/ If fnameBCEE Then 'es!onse#Write.E(ello E M fname M EFBbr @CE/ 'es!onse#Write.E(o are )ou to%a)9E/ &n% If DC B@bo%)C B@htmlC (utput 4esult> Jour name> Submit *ollections *ollection Descri!tion 0ontents 0ontains all the items appended to the application through a script command #tatic(b5ects 0ontains all the ob5ects appended to the application with the T!" Rob5ectS tag Metho%s Metho% Descri!tion 0ontents.4emove <eletes an item from the 0ontents collection 0ontents.4emoveAll-. <eletes all items from the 0ontents collection "ock ,revents other users from modifying the variables in the Application ob5ect 3nlock %nables other users to modify the variables in the Application ob5ect -after it has been locked using the "ock method. &$ents &$ent Descri!tion ApplicationM(n%nd (ccurs when all user sessions are over, and the application ends ApplicationM(n#tart (ccurs before the first new session is created -when the Application ob5ect is first referenced. ASP A!!licationL4nStart an% A!!licationL4n&n% &$ents A!!licationL4nStart &$ent The ApplicationM(n#tart event occurs before the first new session is created -when the Application ob5ect is first referenced.. This event is placed in the @lobal.asa file. 1ote: 4eferencing to a #ession, 4equest, or 4esponse ob5ects in the ApplicationM(n#tart event script will cause an error. A!!licationL4n&n% &$ent The ApplicationM(n%nd event occurs when the application ends -when the web server stops.. This event is placed in the @lobal.asa file. 1ote: The !ap,ath method cannot be used in the ApplicationM(n%nd code. S)nta3 Rscript languageO2vbscript2 runatO2server2S #ub ApplicationM(n#tart . . . %nd #ub #ub ApplicationM(n%nd . . . %nd #ub R8scriptS &3am!les @lobal.asa> Rscript languageO2vbscript2 runatO2server2S #ub ApplicationM(n%nd-. Application-2totvisitors2.OApplication-2visitors2. %nd #ub #ub ApplicationM(n#tart Application-2visitors2.OC %nd #ub #ub #essionM(n#tart Application."ock Application-2visitors2.OApplication-2visitors2.[1 Application.3n"ock %nd #ub #ub #essionM(n%nd Application."ock Application-2visitors2.OApplication-2visitors2.11 Application.3n"ock %nd #ub R8scriptS To display the number of current visitors in an A#, file> RhtmlS RheadS R8headS RbodyS RpS There are RXresponse.write-Application-2visitors2..XS online nowT R8pS R8bodyS R8htmlS ASP Session 4b7ect The Session ob7ect is use% to store information aboutH or change settings for a user session# Variables store% in the Session ob7ect hol% information about one single userH an% are a$ailable to all !ages in one a!!lication# Session 4b7ect When you are working with an application, you open it, do some changes and then you close it. This is much like a #ession. The computer knows who you are. $t knows when you start the application and when you end. Dut on the internet there is one problem> the web server does not know who you are and what you do because the TT, address doesn/t maintain state. A#, solves this problem by creating a unique cookie for each user. The cookie is sent to the client and it contains information that identifies the user. This interface is called the #ession ob5ect. The #ession ob5ect is used to store information about, or change settings for a user session. Hariables stored in the #ession ob5ect hold information about one single user, and are available to all pages in one application. 0ommon information stored in session variables are name, id, and preferences. The server creates a new #ession ob5ect for each new user, and destroys the #ession ob5ect when the session expires. The #ession ob5ect/s collections, properties, methods, and events are described below> *ollections *ollection Descri!tion 0ontents 0ontains all the items appended to the session through a script command #tatic(b5ects 0ontains all the ob5ects appended to the session with the T!" Rob5ectS tag Pro!erties Pro!ert) Descri!tion 0ode,age #pecifies the character set that will be used when displaying dynamic content "0$< #ets or returns an integer that specifies a location or region. 0ontents like date, time, and currency will be displayed according to that location or region #ession$< 4eturns a unique id for each user. The unique id is generated by the server Timeout #ets or returns the timeout period -in minutes. for the #ession ob5ect in this application Metho%s Metho% Descri!tion Abandon <estroys a user session 0ontents.4emove <eletes an item from the 0ontents collection 0ontents.4emoveAll-. <eletes all items from the 0ontents collection &$ents &$ent Descri!tion #essionM(n%nd (ccurs when a session ends #essionM(n#tart (ccurs when a session starts ASP SessionL4nStart an% SessionL4n&n% &$ents SessionL4nStart &$ent The #essionM(n#tart event occurs when the server creates a session. This event is placed in the @lobal.asa file. SessionL4n&n% &$ent The #essionM(n%nd event occurs when the session ends -abandoned or times out.. This event is placed in the @lobal.asa file. 1ote: The !ap,ath method cannot be used in the #essionM(n%nd code. S)nta3 Rscript languageO2vbscript2 runatO2server2S #ub #essionM(n#tart . . . %nd #ub #ub #essionM(n%nd . . . %nd #ub R8scriptS &3am!les @lobal.asa> Rscript languageO2vbscript2 runatO2server2S #ub ApplicationM(n%nd-. Application-2totvisitors2.OApplication-2visitors2. %nd #ub #ub ApplicationM(n#tart Application-2visitors2.OC %nd #ub #ub #essionM(n#tart Application."ock Application-2visitors2.OApplication-2visitors2.[1 Application.3n"ock %nd #ub #ub #essionM(n%nd Application."ock Application-2visitors2.OApplication-2visitors2.11 Application.3n"ock %nd #ub R8scriptS To display the number of current visitors in an A#, file> RhtmlS RheadS R8headS RbodyS RpS There are RXresponse.write-Application-2visitors2..XS online nowT R8pS R8bodyS R8htmlS ASP Ser$er 4b7ect The ASP Ser$er ob7ect is use% to access !ro!erties an% metho%s on the ser$er# Ser$er 4b7ect The A#, #erver ob5ect is used to access properties and methods on the server. $ts properties and methods are described below> Pro!erties Pro!ert) Descri!tion #criptTimeout #ets or returns the maximum number of seconds a script can run before it is terminated Metho%s Metho% Descri!tion 0reate(b5ect 0reates an instance of an ob5ect %xecute %xecutes an A#, file from inside another A#, file @et"ast%rror-. 4eturns an A#,%rror ob5ect that describes the error condition that occurred ASP ASP&rror 4b7ect The A#,%rror ob5ect is used to display detailed information of any error that occurs in scripts in an A#, page. The ASP&rror 4b7ect The A#,%rror ob5ect was implemented in A#, 9.C and is available in $$#7 and later. The A#,%rror ob5ect is used to display detailed information of any error that occurs in scripts in an A#, page. The A#,%rror ob5ect is created when #erver.@et"ast%rror is called, so the error information can only be accessed by using the #erver.@et"ast%rror method. ASP 0ileS)stem4b7ect 4b7ect The 0ileS)stem4b7ect ob7ect is use% to access the file s)stem on the ser$er# The 0ileS)stem4b7ect 4b7ect The 'ile#ystem(b5ect ob5ect is used to access the file system on the server. This ob5ect can manipulate files, folders, and directory paths. $t is also possible to retrieve file system information with this ob5ect. The following code creates a text file -c>Itest.txt. and then writes some text to the file> RX dim fs,fname set fsO#erver.0reate(b5ect-2#cripting.'ile#ystem(b5ect2. set fnameOfs.0reateText'ile-2c>Itest.txt2,true. fname.Write"ine-2ello WorldT2. fname.0lose set fnameOnothing set fsOnothing XS Acti$eN Data 4b7ectsH Accessing a Database from Acti$e Ser$er Page# AD4 can be use% to access %atabases from )our eb !ages# Accessing a Database from an ASP Page The common way to access a database from inside an A#, page is to> 1. 0reate an A<( connection to a database *. (pen the database connection 9. 0reate an A<( recordset 6. (pen the recordset 7. %xtract the data you need from the recordset :. 0lose the recordset =. 0lose the connection What is AD49 A<( is a !icrosoft technology A<( stands for Active+ Data 4b5ects A<( is a !icrosoft Active1+ component A<( is automatically installed with !icrosoft $$# A<( is a programming interface to access data in a database AD4 Database *onnection Before a %atabase can be accesse% from a eb !ageH a %atabase connection has to be establishe%# *reate a DS1-less Database *onnection The easiest way to connect to a database is to use a <#)1less connection. A <#)1less connection can be used against any !icrosoft Access database on your web site. $f you have a database called 2northwind.mdb2 located in a web directory like 2c>8webdata82, you can connect to the database with the following A#, code> RX set connO#erver.0reate(b5ect-2A<(<D.0onnection2. conn.,roviderO2!icrosoft.Aet.("%<D.6.C2 conn.(pen 2c>8webdata8northwind.mdb2 XS )ote, from the example above, that you have to specify the !icrosoft Access database driver -,rovider. and the physical path to the database on your computer. *reate an 4DB* Database *onnection $f you have an (<D0 database called 2northwind2 you can connect to the database with the following A#, code> RX set connO#erver.0reate(b5ect-2A<(<D.0onnection2. conn.(pen 2northwind2 XS With an (<D0 connection, you can connect to any database, on any computer in your network, as long as an (<D0 connection is available. An 4DB* *onnection to an MS Access Database ere is how to create a connection to a !# Access <atabase> 1. (pen the 4DB* icon in your 0ontrol ,anel. *. 0hoose the S)stem DS1 tab. 9. 0lick on A%% in the #ystem <#) tab. 6. Select the !icrosoft Access <river. 0lick 0inish# 7. $n the next screen, click Select to locate the database. :. @ive the database a Data Source 1ame -<#).. =. 0lick 45. )ote that this configuration has to be done on the computer where your web site is located. $f you are running ,ersonal Web #erver -,W#. or $nternet $nformation #erver -$$#. on your own computer, the instructions above will work, but if your web site is located on a remote server, you have to have physical access to that server, or ask your web host to do this for you. The AD4 *onnection 4b7ect The A<( 0onnection ob5ect is used to create an open connection to a data source. Through this connection, you can access and manipulate a database. *onnection 4b7ect The A<( 0onnection (b5ect is used to create an open connection to a data source. Through this connection, you can access and manipulate a database. $f you want to access a database multiple times, you should establish a connection using the 0onnection ob5ect. Jou can also make a connection to a database by passing a connection string via a 0ommand or 4ecordset ob5ect. owever, this type of connection is only good for one specific, single query. ProgID set ob50onnectionO#erver.0reate(b5ect-2A<(<D.connection2. AD4 'ecor%set To be able to rea% %atabase %ataH the %ata must first be loa%e% into a recor%set# *reate an AD4 Table 'ecor%set After an A<( <atabase 0onnection has been created, as demonstrated in the previous chapter, it is possible to create an A<( 4ecordset. #uppose we have a database named 2)orthwind2, we can get access to the 20ustomers2 table inside the database with the following lines> RX set connO#erver.0reate(b5ect-2A<(<D.0onnection2. conn.,roviderO2!icrosoft.Aet.("%<D.6.C2 conn.(pen 2c>8webdata8northwind.mdb2 set rsO#erver.0reate(b5ect-2A<(<D.recordset2. rs.(pen 20ustomers2, conn XS *reate an AD4 SJL 'ecor%set We can also get access to the data in the 20ustomers2 table using #Z"> RX set connO#erver.0reate(b5ect-2A<(<D.0onnection2. conn.,roviderO2!icrosoft.Aet.("%<D.6.C2 conn.(pen 2c>8webdata8northwind.mdb2 set rsO#erver.0reate(b5ect-2A<(<D.recordset2. rs.(pen 2#elect W from 0ustomers2, conn XS &3tract Data from the 'ecor%set After a recordset is opened, we can extract data from recordset. #uppose we have a database named 2)orthwind2, we can get access to the 20ustomers2 table inside the database with the following lines> RX set connO#erver.0reate(b5ect-2A<(<D.0onnection2. conn.,roviderO2!icrosoft.Aet.("%<D.6.C2 conn.(pen 2c>8webdata8northwind.mdb2 set rsO#erver.0reate(b5ect-2A<(<D.recordset2. rs.(pen 2#elect W from 0ustomers2, conn for each x in rs.fields response.write-x.name. response.write-2 O 2. response.write-x.value. next XS The AD4 'ecor%set 4b7ect The A<( 4ecordset ob5ect is used to hold a set of records from a database table. AD4 Dis!la) The most common a) to %is!la) %ata from a recor%setH is to %is!la) the %ata in an (TML table# Dis!la) the 0iel% 1ames an% 0iel% Values We have a database named 2)orthwind2 and we want to display the data from the 20ustomers2 table -remember to save the file with an .asp extension.> RhtmlS RbodyS RX set connO#erver.0reate(b5ect-2A<(<D.0onnection2. conn.,roviderO2!icrosoft.Aet.("%<D.6.C2 conn.(pen 2c>8webdata8northwind.mdb2 set rs O #erver.0reate(b5ect-2A<(<D.recordset2. rs.(pen 2#%"%0T W '4(! 0ustomers2, conn do until rs.%(' for each x in rs.'ields 4esponse.Write-x.name. 4esponse.Write-2 O 2. 4esponse.Write-x.value Y 2Rbr 8S2. next 4esponse.Write-2Rbr 8S2. rs.!ove)ext loop rs.close conn.close XS R8bodyS R8htmlS ere is the result> 0ustomer$< O A"'L$ 0ompany)ame O Alfreds 'utterkiste 0ontact)ame O !aria Anders 0ontactTitle O #ales 4epresentative Address O (bere #tr. 7= 0ity O Derlin ,ostal0ode O 1**C\ 0ountry O @ermany 0ustomer$< O D%4@# 0ompany)ame O Derglunds snabbk]p 0ontact)ame O 0hristina Derglund 0ontactTitle O (rder Administrator Address O Derguvsv^gen B 0ity O "ule_ ,ostal0ode O #1\7B ** 0ountry O #weden 0ustomer$< O 0%)T0 0ompany)ame O 0entro comercial !octe&uma 0ontact)ame O 'rancisco 0hang 0ontactTitle O !arketing !anager Address O #ierras de @ranada \\\9 0ity O !`xico <.'. ,ostal0ode O C7C** 0ountry O !exico .... .... .... Dis!la) the 0iel% 1ames an% 0iel% Values in an (TML Table We can also display the data from the 20ustomers2 table inside an T!" table with the following lines -remember to save the file with an .asp extension.> RhtmlS RbodyS RX set connO#erver.0reate(b5ect-2A<(<D.0onnection2. conn.,roviderO2!icrosoft.Aet.("%<D.6.C2 conn.(pen 2c>8webdata8northwind.mdb2 set rs O #erver.0reate(b5ect-2A<(<D.recordset2. rs.(pen 2#%"%0T 0ompanyname, 0ontactname '4(! 0ustomers2, conn XS Rtable borderO212 widthO21CCX2S RXdo until rs.%('XS RtrS RXfor each x in rs.'ieldsXS RtdSRX4esponse.Write-x.value.XSR8tdS RXnext rs.!ove)extXS R8trS RXloop rs.close conn.close XS R8tableS R8bodyS R8htmlS ere is the result> Alfreds 'utterkiste !aria Anders Derglunds snabbk]p 0hristina Derglund 0entro comercial !octe&uma 'rancisco 0hang A%% (ea%ers to the (TML Table We want to add headers to the T!" table to make it more readable -remember to save the file with an .asp extension.> RhtmlS RbodyS RX set connO#erver.0reate(b5ect-2A<(<D.0onnection2. conn.,roviderO2!icrosoft.Aet.("%<D.6.C2 conn.(pen 2c>8webdata8northwind.mdb2 set rs O #erver.0reate(b5ect-2A<(<D.recordset2. sqlO2#%"%0T 0ompanyname, 0ontactname '4(! 0ustomers2 rs.(pen sql, conn XS Rtable borderO212 widthO21CCX2S RtrS RXfor each x in rs.'ields response.write-2RthS2 Y x.name Y 2R8thS2. nextXS R8trS RXdo until rs.%('XS RtrS RXfor each x in rs.'ieldsXS RtdSRX4esponse.Write-x.value.XSR8tdS RXnext rs.!ove)extXS R8trS RXloop rs.close conn.close XS R8tableS R8bodyS R8htmlS ere is the result> *om!an)name *ontactname Alfreds 'utterkiste !aria Anders Derglunds snabbk]p 0hristina Derglund 0entro comercial !octe&uma 'rancisco 0hang AD4 Jueries We ma) use SJL to create +ueries to s!ecif) onl) a selecte% set of recor%s an% fiel%s to $ie# Dis!la) Selecte% Data We want to display only the records from the 20ustomers2 table that have a 20ompanyname2 that starts with an A -remember to save the file with an .asp extension.> RhtmlS RbodyS RX set connO#erver.0reate(b5ect-2A<(<D.0onnection2. conn.,roviderO2!icrosoft.Aet.("%<D.6.C2 conn.(pen 2c>8webdata8northwind.mdb2 set rsO#erver.0reate(b5ect-2A<(<D.recordset2. sqlO2#%"%0T 0ompanyname, 0ontactname '4(! 0ustomers W%4% 0ompany)ame "$L% /AX/2 rs.(pen sql, conn XS Rtable borderO212 widthO21CCX2S RtrS RXfor each x in rs.'ields response.write-2RthS2 Y x.name Y 2R8thS2. nextXS R8trS RXdo until rs.%('XS RtrS RXfor each x in rs.'ieldsXS RtdSRX4esponse.Write-x.value.XSR8tdS RXnext rs.!ove)extXS R8trS RXloop rs.close conn.closeXS R8tableS R8bodyS R8htmlS ere is the result> *om!an)name *ontactname Alfreds 'utterkiste !aria Anders <isplay records where 20ompanyname2 starts with an A ow to display only the records from the 20ustomers2 table that have a 20ompanyname2 that starts with an A. ASP Source: RhtmlS RbodyS RX set connO#erver.0reate(b5ect-2A<(<D.0onnection2. conn.,roviderO2!icrosoft.Aet.("%<D.6.C2 conn.(pen-#erver.!appath-28db8northwind.mdb2.. set rs O #erver.0reate(b5ect-2A<(<D.recordset2. sqlO2#%"%0T 0ompanyname, 0ontactname '4(! 0ustomers W%4% 0ompany)ame "$L% /AX/2 rs.(pen sql, conn XS Rtable borderO212 widthO21CCX2S RtrS RXfor each x in rs.'ields response.write-2RthS2 Y x.name Y 2R8thS2. nextXS R8trS RXdo until rs.%('XS RtrS RXfor each x in rs.'ieldsXS RtdSRX4esponse.Write-x.value.XSR8tdS RXnext rs.!ove)extXS R8trS RXloop rs.close conn.close XS R8tableS R8bodyS R8htmlS 4ut!ut 'esult: *om!an)name *ontactname Alfreds 'utterkiste !aria Anders "et the user choose filter "et the user choose which country to show customers from. ASP Source: RhtmlS RbodyS RX set connO#erver.0reate(b5ect-2A<(<D.0onnection2. conn.,roviderO2!icrosoft.Aet.("%<D.6.C2 conn.(pen-#erver.!appath-28db8northwind.mdb2.. set rsO#erver.0reate(b5ect-2A<(<D.recordset2. sqlO2#%"%0T <$#T$)0T 0ountry '4(! 0ustomers (4<%4 DJ 0ountry2 rs.(pen sql,conn countryOrequest.form-2country2. XS Rform methodO2post2S 0hoose 0ountry Rselect nameO2country2S RX do until rs.%(' response.write-2Roption2. if rs.fields-2country2.Ocountry then response.write-2 selected2. end if response.write-2S2. response.write-rs.fields-20ountry2.. rs.!ove)ext loop rs.0lose set rsO)othing XS R8selectS Rinput typeO2submit2 valueO2#how customers2S R8formS RX if countryRS22 then sqlO2#%"%0T 0ompanyname,0ontactname,0ountry '4(! 0ustomers W%4% countryO/2 Y country Y 2/2 set rsO#erver.0reate(b5ect-2A<(<D.4ecordset2. rs.(pen sql,conn XS Rtable widthO21CCX2 cellspacingO2C2 cellpaddingO2*2 borderO212S RtrS RthS0ompanynameR8thS RthS0ontactnameR8thS RthS0ountryR8thS R8trS RX do until rs.%(' response.write-2RtrS2. response.write-2RtdS2 Y rs.fields-2companyname2. Y 2R8tdS2. response.write-2RtdS2 Y rs.fields-2contactname2. Y 2R8tdS2. response.write-2RtdS2 Y rs.fields-2country2. Y 2R8tdS2. response.write-2R8trS2. rs.!ove)ext loop rs.close conn.0lose set rsO)othing set connO)othingXS R8tableS RX end if XS R8bodyS R8htmlS 4ut!ut 'esult: 0hoose 0ountry Show customers D4 A%% 'ecor%s We ma) use the SJL I1S&'T I1T4 comman% to a%% a recor% to a table in a %atabase# A%% a 'ecor% to a Table in a Database We want to add a new record to the 0ustomers table in the )orthwind database. We first create a form that contains the fields we want to collect data from> RhtmlS RbodyS Rform methodO2post2 actionO2demoMadd.asp2S RtableS RtrS RtdS0ustomer$<>R8tdS RtdSRinput nameO2custid2SR8tdS R8trSRtrS RtdS0ompany )ame>R8tdS RtdSRinput nameO2compname2SR8tdS R8trSRtrS RtdS0ontact )ame>R8tdS RtdSRinput nameO2contname2SR8tdS R8trSRtrS RtdSAddress>R8tdS RtdSRinput nameO2address2SR8tdS R8trSRtrS RtdS0ity>R8tdS RtdSRinput nameO2city2SR8tdS R8trSRtrS RtdS,ostal 0ode>R8tdS RtdSRinput nameO2postcode2SR8tdS R8trSRtrS RtdS0ountry>R8tdS RtdSRinput nameO2country2SR8tdS R8trS R8tableS Rbr 8SRbr 8S Rinput typeO2submit2 valueO2Add )ew2S Rinput typeO2reset2 valueO20ancel2S R8formS R8bodyS R8htmlS When the user presses the submit button the form is sent to a file called 2demoMadd.asp2. The 2demoMadd.asp2 file contains the code that will add a new record to the 0ustomers table> RhtmlS RbodyS RX set connO#erver.0reate(b5ect-2A<(<D.0onnection2. conn.,roviderO2!icrosoft.Aet.("%<D.6.C2 conn.(pen 2c>8webdata8northwind.mdb2 sqlO2$)#%4T $)T( customers -customer$<,companyname,2 sqlOsql Y 2contactname,address,city,postalcode,country.2 sqlOsql Y 2 HA"3%# 2 sqlOsql Y 2-/2 Y 4equest.'orm-2custid2. Y 2/,2 sqlOsql Y 2/2 Y 4equest.'orm-2compname2. Y 2/,2 sqlOsql Y 2/2 Y 4equest.'orm-2contname2. Y 2/,2 sqlOsql Y 2/2 Y 4equest.'orm-2address2. Y 2/,2 sqlOsql Y 2/2 Y 4equest.'orm-2city2. Y 2/,2 sqlOsql Y 2/2 Y 4equest.'orm-2postcode2. Y 2/,2 sqlOsql Y 2/2 Y 4equest.'orm-2country2. Y 2/.2 on error resume next conn.%xecute sql,recaffected if errRSC then 4esponse.Write-2)o update permissionsT2. else 4esponse.Write-2Rh9S2 Y recaffected Y 2 record addedR8h9S2. end if conn.close XS R8bodyS R8htmlS Im!ortant $f you use the #Z" $)#%4T command be aware of the following> $f the table contains a primary key, make sure to append a unique, non1)ull value to the primary key field -if not, the provider may not append the record, or an error occurs. $f the table contains an Auto)umber field, do not include this field in the #Z" $)#%4T command -the value of this field will be taken care of automatically by the provider. What about 0iel%s With no Data9 $n a !# Access database, you can enter &ero1length strings -22. in Text, yperlink, and !emo fields $' you set the Allowaero"ength property to Jes. 1ote: )ot all databases support &ero1length strings and may cause an error when a record with blank fields is added. $t is important to check what data types your database supports. AD4 I!%ate 'ecor%s We ma) use the SJL IPDAT& comman% to u!%ate a recor% in a table in a %atabase# I!%ate a 'ecor% in a Table We want to update a record in the 0ustomers table in the )orthwind database. We first create a table that lists all records in the 0ustomers table> RhtmlS RbodyS RX set connO#erver.0reate(b5ect-2A<(<D.0onnection2. conn.,roviderO2!icrosoft.Aet.("%<D.6.C2 conn.(pen 2c>8webdata8northwind.mdb2 set rsO#erver.0reate(b5ect-2A<(<D.4ecordset2. rs.open 2#%"%0T W '4(! customers2,conn XS Rh*S"ist <atabaseR8h*S Rtable borderO212 widthO21CCX2S RtrS RX for each x in rs.'ields response.write-2RthS2 Y ucase-x.name. Y 2R8thS2. next XS R8trS RX do until rs.%(' XS RtrS Rform methodO2post2 actionO2demoMupdate.asp2S RX for each x in rs.'ields if lcase-x.name.O2customerid2 thenXS RtdS Rinput typeO2submit2 nameO2customer$<2 valueO2RXOx.valueXS2S R8tdS RXelseXS RtdSRX4esponse.Write-x.value.XSR8tdS RXend if next XS R8formS RXrs.!ove)extXS R8trS RX loop conn.close XS R8tableS R8bodyS R8htmlS $f the user clicks on the button in the 2customer$<2 column he or she will be taken to a new file called 2demoMupdate.asp2. The 2demoMupdate.asp2 file contains the source code on how to create input fields based on the fields from one record in the database table. $t also contains a 23pdate record2 button that will save your changes> RhtmlS RbodyS Rh*S3pdate 4ecordR8h*S RX set connO#erver.0reate(b5ect-2A<(<D.0onnection2. conn.,roviderO2!icrosoft.Aet.("%<D.6.C2 conn.(pen 2c>8webdata8northwind.mdb2 cidO4equest.'orm-2customer$<2. if 4equest.form-2companyname2.O22 then set rsO#erver.0reate(b5ect-2A<(<D.4ecordset2. rs.open 2#%"%0T W '4(! customers W%4% customer$<O/2 Y cid Y 2/2,conn XS Rform methodO2post2 actionO2demoMupdate.asp2S RtableS RXfor each x in rs.'ieldsXS RtrS RtdSRXOx.nameXSR8tdS RtdSRinput nameO2RXOx.nameXS2 valueO2RXOx.valueXS2SR8tdS RXnextXS R8trS R8tableS Rbr 8SRbr 8S Rinput typeO2submit2 valueO23pdate record2S R8formS RX else sqlO23,<AT% customers #%T 2 sqlOsql Y 2companynameO/2 Y 4equest.'orm-2companyname2. Y 2/,2 sqlOsql Y 2contactnameO/2 Y 4equest.'orm-2contactname2. Y 2/,2 sqlOsql Y 2addressO/2 Y 4equest.'orm-2address2. Y 2/,2 sqlOsql Y 2cityO/2 Y 4equest.'orm-2city2. Y 2/,2 sqlOsql Y 2postalcodeO/2 Y 4equest.'orm-2postalcode2. Y 2/,2 sqlOsql Y 2countryO/2 Y 4equest.'orm-2country2. Y 2/2 sqlOsql Y 2 W%4% customer$<O/2 Y cid Y 2/2 on error resume next conn.%xecute sql if errRSC then response.write-2)o update permissionsT2. else response.write-24ecord 2 Y cid Y 2 was updatedT2. end if end if conn.close XS R8bodyS R8htmlS AD4 Delete 'ecor%s We ma) use the SJL D&L&T& comman% to %elete a recor% in a table in a %atabase# Delete a 'ecor% in a Table We want to delete a record in the 0ustomers table in the )orthwind database. We first create a table that lists all records in the 0ustomers table> RhtmlS RbodyS RX set connO#erver.0reate(b5ect-2A<(<D.0onnection2. conn.,roviderO2!icrosoft.Aet.("%<D.6.C2 conn.(pen 2c>8webdata8northwind.mdb2 set rsO#erver.0reate(b5ect-2A<(<D.4ecordset2. rs.open 2#%"%0T W '4(! customers2,conn XS Rh*S"ist <atabaseR8h*S Rtable borderO212 widthO21CCX2S RtrS RX for each x in rs.'ields response.write-2RthS2 Y ucase-x.name. Y 2R8thS2. next XS R8trS RX do until rs.%(' XS RtrS Rform methodO2post2 actionO2demoMdelete.asp2S RX for each x in rs.'ields if x.nameO2customer$<2 thenXS RtdS Rinput typeO2submit2 nameO2customer$<2 valueO2RXOx.valueXS2S R8tdS RXelseXS RtdSRX4esponse.Write-x.value.XSR8tdS RXend if next XS R8formS RXrs.!ove)extXS R8trS RX loop conn.close XS R8tableS R8bodyS R8htmlS $f the user clicks on the button in the 2customer$<2 column he or she will be taken to a new file called 2demoMdelete.asp2. The 2demoMdelete.asp2 file contains the source code on how to create input fields based on the fields from one record in the database table. $t also contains a 2<elete record2 button that will delete the current record> RhtmlS RbodyS Rh*S<elete 4ecordR8h*S RX set connO#erver.0reate(b5ect-2A<(<D.0onnection2. conn.,roviderO2!icrosoft.Aet.("%<D.6.C2 conn.(pen 2c>8webdata8northwind.mdb2 cidO4equest.'orm-2customer$<2. if 4equest.form-2companyname2.O22 then set rsO#erver.0reate(b5ect-2A<(<D.4ecordset2. rs.open 2#%"%0T W '4(! customers W%4% customer$<O/2 Y cid Y 2/2,conn XS Rform methodO2post2 actionO2demoMdelete.asp2S RtableS RXfor each x in rs.'ieldsXS RtrS RtdSRXOx.nameXSR8tdS RtdSRinput nameO2RXOx.nameXS2 valueO2RXOx.valueXS2SR8tdS RXnextXS R8trS R8tableS Rbr 8SRbr 8S Rinput typeO2submit2 valueO2<elete record2S R8formS RX else sqlO2<%"%T% '4(! customers2 sqlOsql Y 2 W%4% customer$<O/2 Y cid Y 2/2 on error resume next conn.%xecute sql if errRSC then response.write-2)o update permissionsT2. else response.write-24ecord 2 Y cid Y 2 was deletedT2. end if end if conn.close XS R8bodyS R8htmlS ListH &%itH I!%ateH an% Delete Database 'ecor%s "ist, edit, update, and delete database records List Database Table 0lick on a button to modify a record. 14 01AM& L1AM& P(41& &MAIL (4M&PA;& DAT&ADD&D 16 Ter5e Deck 77 :: == \\ tert5eUsomewere.com www.ama&on.com 181B8*CC1 =>67>6= A! 17 Aan 4efsnes :: == BB 5aniUw9schools.com http>8www.w9schools.com =8118*CCC 1>C1>7: ,! 39 Torleif 4asmussen == BB \\ )8A )8A 68*:8*CCC 9>6:>61 A! 46 anton chek B9B99 apaUkabar.com www.yahoo.com 68*78*CCC =>1=>67 A! 48 stale refsnes 7771 1**96 refsnesUhotmail.com http>88www.w9schools.com 78918*CCC 11>16>99 A! 52 hari prawin \B61C1 \7B\= hariUhari.com www.hari.com 181B8*CC1 =>6=>7B A! 53 ege 4efsnes )8A hegeUsomewhere.com )8A 98**8*CC1 1>97>C1 ,! Hiew source on how to list a database table in an T!" table RXoption explicitXS RhtmlS RheadSRtitleSA<( 1 "ist <atabase 4ecordsR8titleSR8headS RbodyS RX dim conn,rs,x set connO#erver.0reate(b5ect-2A<(<D.0onnection2. conn.providerO2!icrosoft.Aet.("%<D.6.C2 conn.open-server.mappath-28db8database.mdb2.. set rsO#erver.0reate(b5ect-2A<(<D.4ecordset2. rs.open 2#%"%0T W '4(! tbl@uestDook2,conn XS Rh*S"ist <atabase TableR8h*S RpS0lick on a button to modify a record.R8pS Rtable borderO212 widthO21CCX2S Rtr bgcolorO2VbCc6de2S RX for each x in rs.'ields response.write-2RthS2 Y ucase-x.name. Y 2R8thS2. next XS R8trS RXdo until rs.%('XS Rtr bgcolorO2VfCfCfC2S Rform methodO2post2 actionO2demoMdbMedit.asp2 targetO2Mblank2S RX for each x in rs.'ields if x.nameO2no2 thenXS RtdSRinput typeO2submit2 nameO2no2 valueO2RXOx.valueXS2SR8tdS RXelseXS RtdSRX4esponse.Write-x.value.XS R8tdS RXend if next XS R8formS RXrs.!ove)extXS R8trS RX loop rs.close set rsOnothing conn.close set connOnothing XS R8tableS RpSRa hrefO2showcode.aspKsourceOdemoMdbMlist.asp2SHiew source on how to list a database table in an T!" tableR8aSR8pS RpSRbS)ote>R8bS $f you click on a button in the 2no2 column a new page will open. (n the new page you may look at the source on how to create input fields based on the fields from one record in the database table.R8pS R8bodyS R8htmlS &%it Database Table fname lname phone email homepage Save Delete Hiew source on how to create input fields based on the fields from one record in the database table. 1ote: $f you click on 2#ave2 or 2<elete2 a new page will open. (n the new page you may look at the source on how to submit changes to, or delete from a database table. RX noO4equest.'orm-2no2. if noO22 then response.end set connO#erver.0reate(b5ect-2A<(<D.0onnection2. conn.providerO2!icrosoft.Aet.("%<D.6.C2 conn.open-server.mappath-28db8database.mdb2.. set rs O #erver.0reate(b5ect-2A<(<D.4ecordset2. rs.(pen 2#elect W from tbl@uestDook where tbl@uestDook.EnoFO2 Y no , conn XS RhtmlS RheadS RtitleSA<( 1 %dit <ataDase 4ecordR8titleS R8headS RbodyS Rh*S%dit <atabase TableR8h*S Rform methodO2post2 actionO2demoMdbMsubmit.asp2 targetO2Mblank2S Rinput nameO2no2 typeO2hidden2 valueORXOnoXSS Rtable bgcolorO2VbCc6de2S RX for each x in rs.'ields if x.name RS 2no2 and x.name RS 2dateadded2 thenXS RtrS RtdSRXOx.nameXS R8tdS RtdSRinput nameO2RXOx.nameXS2 valueO2RXOx.valueXS2 si&eO2*C2SR8tdS RXend if next rs.close conn.close XS R8trS R8tableS Rbr 8S Rinput typeO2submit2 nameO2action2 valueO2#ave2S Rinput typeO2submit2 nameO2action2 valueO2<elete2S R8formS RpSRa hrefO2showcode.aspKsourceOdemoMdbMedit.asp2SHiew source on how to create input fields based on the fields from one record in the database tableR8aS.R8pS RpSRbS)ote>R8bS $f you click on 2#ave2 or 2<elete2 a new page will open. (n the new page you may look at the source on how to submit changes to, or delete from a database table.R8pS R8bodyS R8htmlS A%% a 1e 'ecor% to a Database Adding a 9ecord 'name "name ,hone %mail homepage Add Record Hiew source on how to create input fields based on the fields in the database table. 1ote: $f you click on 2Add 4ecord2 a new page will open. (n the new page you may look at the source on how to add a record to a database table. RhtmlS RheadS RtitleSA<( 1 Add <ataDase 4ecordR8titleS R8headS RbodyS RX set connO#erver.0reate(b5ect-2A<(<D.0onnection2. conn.,roviderO2!icrosoft.Aet.("%<D.6.C2 conn.(pen-#erver.mappath-28db8database.mdb2.. set rs O #erver.0reate(b5ect-2A<(<D.4ecordset2. rs.(pen 2select W from tbl@uestDook2, conn XS Rh*SAdding a 4ecordR8h*S Rform methodO2post2 actionO2demoMdbMnew.asp2 targetO2Mblank2S Rtable bgcolorO2VbCc6de2S RX for each x in rs.'ields if x.name RS 2no2 and x.name RS 2dateadded2 thenXS RtrS RtdSRXOx.nameXSR8tdS RtdSRinput nameO2RXOx.nameXS2 valueO2)8A2 si&eO2*C2SR8tdS RX end if next rs.close conn.close XS R8trSR8tableS Rbr 8S Rinput typeO2submit2 nameO2action2 valueO2Add 4ecord2S R8formS RpSRa hrefO2showcode.aspKsourceOdemoMdbMadd.asp2SHiew source on how to create input fields based on the fields in the database tableR8aS.R8pS RpSRbS)ote>R8bS $f you click on 2Add 4ecord2 a new page will open. (n the new page you may look at the source on how to add a record to a database table.R8pS R8bodyS R8htmlS Lecture <A-"? Introducing Visual InterDev and te World Wide Web $isual Inter%ev, the long"awaited -eb application development tool from +icrosoft, is finally here. +any developers are applauding its features and the application development needs that it addresses. %evelopers now have a tool similar to other application development tools li'e $isual :asic and $isual ;<< that they can use to create their -eb applications. 4o more downloading the latest beta copy of a single"focused tool from the -eb. ,ou now have a tool that integrates many of the popular components and technologies. %uring the first day, the conte)t for $isual Inter%ev will be set, and you(ll be introduce to some of the latest developments concerning the Internet and the ---. ,ou will learn about the importance of the Internet. ,ou also will learn about the rising number of intranets, or private internets, that are growing within many companies. ,ou will see how the --- has become ubi8uitous and the implications that it has for individuals and businesses. In discussing the ---, you will discover the differences between static and dynamic web pages and what you should focus on for the future. ,ou will then be introduced to the reasons for having an application development tool for the -eb. *inally, you will get a glimpse of $isual Inter%ev. The Im!ortance of the Internet ,ou obviously reali=e the importance of the Internet or you wouldn(t be reading this boo'. The Internet and the -orld -ide -eb are everywhere. ,ou can(t read the newspaper or watch television without seeing some 'ind of reference to the Internet. ;yberspace and the Information #uperhighway have become common vocabulary for a whole new audience. $irtually every television commercial and print ad contains a reference li'e the following: *or more information, visit us at our -eb site at www.whatever.com. The Internet has come a long way since the old A9PA45T days. 7riginally designed for research use by the %epartment of %efense, the Internet has become a haven for millions of people who have e)perienced the value of communicating with people around the world. Internet users have instant access to a plethora of 'nowledge supported by this networ' of networ's. +ost people point to >??> as the beginning of the Internet e)plosion. In the late >?@2s, the academic community began to see the Internet as a valuable tool. Professors and students at universities around the world began using the Internet as a way to gain valuable research and 'nowledge about myriad sub&ects. #ervices such as electronic mail (e" mail!, file transfer capability (ftp!, and newsgroup discussions all contributed to the growth of the Internet audience. Then, in >??>, the 4ational #cience *oundation (4#*!, which was the ma&or funding group for the Internet, dropped most of its financial support and allowed commercial traffic onto the Internet. The door was now open for all types of individuals and businesses to ta'e advantage of this vital communication networ'. -e are truly living in the Information Age, and the Internet has become the primary means for e)panding our hori=ons. The Internet has opened up any number of possibilities for applications by providing a ready"made networ' for businesses to use. Arowth in the Internet has also forced us to rethin' the way we approach life. A student in ;alifornia can communicate with his parents in *lorida via e"mail instead of building up a hefty, long distance telephone bill. In fact, now most families can conduct conversations over the Internet, thereby s'irting the phone companies. -ith the growth of the ---, businesses have been scrambling to gain a presence on the Internet. In >??B, corporate spending on Internet0intranet systems was C>. billion. This figure is e)pected to grow to C.2@ billion by the year .222. %evelopers will play a huge role in helping organi=ations and businesses understand the importance of using the Internet from an application and communication standpoint. The 'ise in Intranets +any companies are reali=ing the benefits of the Internet from within their companies. These organi=ations are creating intranets, which are private, or internal, internets. These intranets have been established initially as an internal communication tool. 5mployees can send e"mail to other employees within the company. Intranets enable private and sensitive corporate information to be distributed and shared within the organi=ation. This new medium of communication has become a very cost"effective solution, especially for geographically dispersed businesses that have employees all over the world. The time to communicate new policies, procedures, and information is immediately reduced along with postage and paper costs. An intranet also can be used for software distribution and for providing access to vital applications. ;ompanies are now starting to put applications li'e survey forms and employee benefit registration forms on their intranets to simplify basic processes. :usinesses also are starting to consider replacing or enhancing their mission"critical applications (li'e accounting, sales order entry, oil and gas trading, and so on! with applications that are secured within an intranet. Intranets are usually protected and secured by means of a firewall that prevents outside intruders from accessing the internal networ'. To the user, there is no difference between accessing the Internet and the company(s intranet. *igure >.> depicts a typical configuration for an intranet. !igure ".". A high level view of an intranet. #un +icrosystems is a perfect e)ample of how a company can save real money in terms of printing, processing, and mailing costs through the use of an intranet. #un has used the Internet to communicate basic corporate information, such as organi=ation charts and geographic office locations. 5mployees can access monthly updates from their ;57 #cott +c4ealy which are presented in audio and video formats. #un also provides information about its products by providing an online product catalog and updates on new products. 5mployee information regarding training, travel, and human resource policies is placed on the intranet. #un even provides an Applications ;hest that gives employees access to a variety of tools that enhance their productivity. Internet performance has become a huge topic of conversation. #ome individuals have even discussed totally redesigning the Internet infrastructure to support the growing number of users. -ithout entering this debate, I would li'e to point out that intranets provide a way to use the Internet while ta'ing more control over performance of your applications. -ith an intranet, a company can use the Internet architecture model while providing the internal infrastructure to guarantee response time and security. Intranet applications also are cost effective from an administration and deployment standpoint. The browser serves as the universal client for all des'tops. The server ma'es the des'top come alive by providing information and database access. %eployment and administration costs are reduced, because you don(t have to reinstall an updated application on everyone(s des'tops as you do when creating proprietary client"server applications. 5lectronic commerce is going to drastically grow in the ne)t few years and with it will come a continued rise in the use of intranets. This section has described intranets as being internal to an organi=ation or business. Private intranets that focus on providing a reliable and secure infrastructure for groups of businesses also are emerging. Technology companies are beginning to prepare for this occurrence. +icrosoft formed an alliance with :ritish Telecommunications and +;I to provide private data networ's for global companies and their customers. Private intranets offer the same reliability, security, and guaranteed response time that a company(s internal intranet provides. The difference between them is that a company(s reach e)tends beyond the internal organi=ation to e)ternal entities. The use of private intranets will continue to rise as application re8uirements e)ceed the current capabilities of the Internet infrastructure. The Ibi+uitous Web The second e)plosion that propelled the Internet into national prominence was the creation of the -orld -ide -eb. The -eb has many origins, but most people point to the time period between >?@?" >??> when the ;onseil 5uropean pour la 9echerche 4ucleaire (;594! 5uropean Daboratory for Particle Physics in Aeneva, #wit=erland, developed its first specifications. Tim :erners"Dee, a researcher for ;594, developed the basic concepts of sharing information through the use of a consistent, universal interface. +ar' Andreessen is credited with developing the first browser (+osaic! for the -eb in >??3. The use of a browser to view the Internet turned attention away from the information stored on the server, focusing more on the user e)perience through the client machine. The browser provided a graphical, point"and"clic' interface for viewing -eb content that made the Internet easier to access. The -eb is the primary service responsible for bringing the Internet into the homes of millions. The -eb is the most popular and useable service. The hyperte)t lin's to a plethora of information allow the user to e)perience a web of 'nowledge. The user can choose the learning path instead of following a se8uential or linear pattern. The most recent numbers estimate that more than EB million people have visited the -eb at least once. -hen sports figures, music celebrities, and news anchors are touting the -eb, you 'now it has become ubi8uitous. The -eb provides an alternate delivery channel for all types of information as well as graphically robust applications. +a&or software vendors are totally revamping their products to ma'e them Internet"enabled. :an's are having to rethin' their strategy of targeting and servicing their customers by providing online ban'ing. :usinesses are establishing a presence on the -eb to offer products and services electronically. The -eb is everywhere, and we must learn how to properly and constructively use its capabilities. The first wave of -eb development involved information publishing. 9udimentary tools were provided to convert documents created with common word processors to the HT+D format of the -eb. HT+D editors also have provided a way to create original documents as well as -eb pages and deploy them on the -eb. As stated, the Internet and the -eb have saved a lot of money for companies in terms of printing, processing, and mailing costs. The -eb has e)tended the notion of te)tual documentation to provide graphical information as well. Araphics, 3% images, audio, and video can truly enhance the user(s e)perience on the -eb. ;ompanies li'e +acromedia and 9ealAudio have contributed to the multimedia e)perience by providing enhanced and animated graphics and audio capability. The 5#P45T #portsFone is one of the most popular sites on the -eb largely due to the way the site employs multimedia. ,ou can download 5#P4 commercials both in audio and video format as well as listen to press conferences and other sporting events. This site does owe some credit to the popularity of 5#P4, but the people would not be visiting the site if it didn(t provide a rich and rewarding e)perience. The second wave of -eb development has been the creation of functional applications. These applications e)tend the simple registration forms commonly seen on -eb sites to become true interactive applications that include database accessibility. These applications can be classified as &ust another phase of client"server. In ta'ing a loo' at the architecture of the -eb, many of the principles have been carried over from client"server architectures. *igure >.. illustrates a typical client"server architecture. !igure ".#. A typical client-server architecture. ;lient"server is a style of computing where the client machine ma'es a re8uest of a server machine. The re8uest is usually a re8uest for information, as in a database re8uest, or for processing, such as updating a database or running a batch process. The client machine ma'es the re8uest, and the server machine fulfills this re8uest. The benefit of client"server systems is that they ta'e advantage of the strengths of each machine or platform. In a typical scenario, the client handles some application logic and the presentation to the user while the server provides the bac'"end processing and database functions. In a typical -eb application, the browser serves as the universal client that sends a re8uest for a web page, interprets the HT+D document, and displays it to the user. The web server receives the re8uest through the HyperTe)t Transport Protocol (HTTP! and returns the re8uired information in HT+D format that the client can understand. #imilar to client"server, you can distribute the application processing and database management portions to varying degrees between the client and the server machine. *igure >.3 depicts a typical -eb"based architecture. !igure ".$. A typical Web-based architecture. The main benefit to -eb"based applications over client"server is found in the deployment. In a -eb"based scenario, you don(t have to deploy a new e)ecutable on each person(s des'top with each new application feature or update. The browser serves as the universal client, providing access to the most current information on the server. $ersion control, software distribution, and systems management costs are significantly reduced for -eb"based applications. A more in"depth discussion concerning how the web client and server interact is warranted here. Historically, -eb applications have been based on HT+D and common gateway interface (;AI! programs on the server. The -eb browser interprets the HT+D tags and appropriately formats the page for the user. A web page can be a combination of formatted te)t, images and graphics, audio, and video. HT+D also allows for the creation of basic forms that contain te)t fields, radio buttons, chec'bo)es, push buttons, and listbo)es. These ob&ects are discussed in more detail on %ay >., Gsing :asic and Advanced HT+D *orm ;ontrols. ;AI programs have typically been used for processing re8uests on the server and distributing information to the client machine. ;AI programs, or scripts, are e)ecutable files that can be built using languages such as G4I1 shell script, Perl, ;, and so on. As information is updated on your database, the ;AI script can handle accessing the data and passing the information bac' down to the client browser. The advantage is that you don(t have to write new HT+D code for every new document or database update. The ;AI server program provides a reusable component that saves development time. I mentioned the HTTP protocol earlier in this chapter. HTTP is the protocol that allows the browser to connect to a web server. HTTP is a stateless protocolH that is, the client and server don(t maintain a persistent connection. The client ma'es a connection to the server and sends a re8uest. The server receives the re8uest, processes it, then terminates the connection. This process is repeated many times during a user session. This 'ind of communication would be li'e having a telephone conversation with a friend where you would say something, hang up the telephone, then dial again to say something else. This dialogue is very tedious. Interactive applications must have some way to maintain state with the user machine in order to provide for the needs of applications li'e sales order processing. +icrosoft and 4etscape have led the charge to develop an effective server process that supports a more interactive state with the client machine. The creation of application programming interfaces, or APIs, has opened up all 'inds of possibilities over the traditional use of ;AI programs. There are several specific benefits to using APIs. *irst, APIs are more efficient than ;AI programs. A ;AI program opens up a process in memory for each client re8uest. APIs e)ecute processes in the same memory address space, eliminating the overhead of separate e)ecuting processes on one machine. :y using this model, APIs use less memory for e)ecuting a process. Also, initiali=ation with the client machine is performed once for all re8uests. Another benefit of APIs is their ability to maintain state. API programs permit a persistent connection between the client and server, which can be a huge benefit when developing an application with moderate to intensive database connectivity. Also, separate re8uests can share information about the client, because the programs remain resident in memory. The main disadvantage to APIs is that they(re proprietary in nature. -hereas ;AI programs are server"independent, APIs are confined to their respective web server platforms. Table >.> presents the most common APIs and their supported server platforms. Table 1#1# The most !o!ular APIsH their res!ecti$e $en%orsH an% su!!orte% ser$er !latforms# API Ven%or Ser$er Platform Su!!orte% $#A,$ !icrosoft !icrosoft $nternet $nformation #erver, ,rocess #oftware ,urveyor Web#erver )#A,$ )etscape )etscape 0ommerce80ommunication #erver W#A,$ (/4eilly Y Associates (/4eilly Y Associates Web#ite To summari=e, the -eb has become popular for a variety of reasons. The -eb provides graphically rich content on a variety of topics to many users. The -eb also supports transaction"based services that enable businesses and consumers to come together in an electronic mar'et. 5)amples include ordering boo's, ma'ing airline reservations, and trading stoc's. Dearning is also significantly enhanced by having access to all 'inds of documents, white papers, and training materials. 4ame the sub&ect, and you can become an e)pert on it in no time at all by accessing the -eb. The Difference Beteen Static an% D)namic Web Pages -eb"based applications have made the transition from solely publishing information to creating an interactive session with the user. #tatic web pages represent those pages that provide information that is nicely formatted in standard HT+D. *or e)ample, a person might be able to re8uest an employee benefit handboo' to become familiar with the latest updates in benefits. #tatic pages are nice, but users want something more. %ynamic web pages are those pages that provide true user interaction. In this model, users interact through the use of server"side programs that provide for an enhanced e)perience. Instead of &ust reading about the latest human resource benefits, employees can register and update their benefits. %ynamic web pages support the building of true interactive applications. 7nce you have read the published flight schedules, you can ma'e airline reservations electronically over the Internet. #toc' bro'erage houses can publish the hottest stoc' tips and then enable you to capitali=e on the investment through online stoc' trading. %ynamic web pages provide a world of new possibilities over static pages. I briefly discussed the use of ;AI and API programs in providing a gateway between your client and server machine in a -eb"based application. Here, I will focus on the ability to use client" and server" side scripts to create dynamic HT+D web pages. ;lient"side script is usually associated with ob&ects on the HT+D page. These ob&ects could be standard HT+D controls or Active1 controls. ;lient"side script is usually included to ma'e up for the limited functionality of HT+D. The script is included in the HT+D page when it is downloaded from the server to the client machine. The script code e)ecutes on the client machine in response to user interaction and program events. :y 'eeping the script in the HT+D page on the server, a developer only has to ma'e changes to centrali=ed code located on the server. The browser downloads the revised web page simplifying the software distribution process. The goal in this model is to 'eep the code resident on the server leaving little or no code on the client machine. #ome e)amples for using client"side script include user interface functions, entry verification, and standard programming functions. Two of the most popular scripting languages are 4etscape(s Iava#cript and +icrosoft(s $:#cript. $isual Inter%ev supports both of these scripting engines, although +icrosoft has implemented its own version of 4etscape(s Iava#cript called I#cript. There are no significant differences between the I#cript and Iava#cript implementation. Another way to create a dynamic e)perience is through the use of Active1 controls and Iava applets. $isual Inter%ev includes and supports the use of both Active1 controls and Iava applets within your application. These controls provide many additional functions from multimedia to database connectivity. :oth Iava#cript and $:#cript are used to interact with these controls e)tending the reach of the interface. #imilar to the use of $isual :asic code with $isual :asic controls, $:#cript and Iava#cript serve as the glue between the browser and the particular control. The process is essentially the same as using a traditional client"server tool li'e $isual :asic. ,ou add a control to your page, setting its methods and properties. 7nce you have established the basic properties, you add scripting code to handle the application logic. $isual Inter%ev incorporates a visual tool for creating client"side script for your Active1 controls. The #cript -i=ard, first included in the Active1 ;ontrol Pad from +icrosoft, provides a visual interface that builds both $:#cript and Iava#cript. $isual Inter%ev also supports the use of Active #erver Pages. Active #erver Pages are a new feature included with Internet Information #erver 3.2H they provide a framewor' for creating dynamic -eb pages. Active #erver Pages are based on the Active1 #cripting engine and enable you to include server"side e)ecutable script directly into an HT+D document. ,ou can create Active #erver Pages using any of the popular scripting languages, including $:#cript, Iava#cript, Perl, and so on. *igure >.E illustrates how an Active #erver Page interacts with a client machine. !igure ".4. This diagram shows how Active Server Pages interact in a Web-based application. ,ou will notice from the diagram that the web clients communicate with the web server through the HTTP protocol. The web server can be on the Internet or within an intranet. The web server is comprised of Internet Information #erver 3.2, which includes the Active1 #erver #cripting engine. The diagram shows the Active #erver pages, or .asp files, where the server"side script resides. These files are simply HT+D pages that contain scripting code. This scripting code e)tends basic HT+D and provides additional functionality for your application. $isual Inter%ev enables you to create Active #erver Pages. #ome of the visual tools within $isual Inter%ev generate much of the server" side script for you. ,ou have the ability to modify this code as well as create your own server"side script. ,ou will get your chance to build Active #erver Pages on %ay >>, 5)tending ,our Application Through Active #erver #cript. The 1ee% for a 1e 5in% of Tool There are many e)tensive and powerful technologies for creating -eb applications, but most tools only focus on a single, specific need. 7ther tools are being developed to address a few needs. %evelopers have been dreaming of the day when they can use a comprehensive, integrated development environment to build their applications. -hy, you as', do you need an integrated tool6 Ta'e a wal' through a typical -eb development effort and loo' at the many different types of tools that you can use to build a -eb"based application. *irst you need an HT+D editor. +any people have created a new function for an old product and made 4otepad the HT+D editor of choice. Table >.. outlines some of the more robust and popular products on the mar'et. Table 1#<# Po!ular (TML e%itors# (TML &%itor Ven%or ot <og ,ro #ausage #oftware oT!eta" ,ro #oftZuad )avi,ress )avisoft 'ront,age !icrosoft +icrosoft also has created add"in products for its 7ffice suite of products that enable HT+D conversion. *or e)ample, a user who is familiar with +icrosoft -ord can use the Internet Assistant for -ord to convert a document to HT+D format for display in a browser. ;hoosing an HT+D editor is only the beginning. To build an application, you must consider the server"side products as well. ,ou have two basic choices, as previously mentioned: ;AI or APIs. If you choose to use ;AI, you will need to find a programming environment based on the language you select. The possible languages include Perl and G4I1 shell scripts, $isual :asic, ;, and ;<<. If you choose an API, you need to select the appropriate API implementation for your application platform(s web server. 9efer to Table >.> for a listing of APIs and their supported web server platforms. API server programs are implemented as dynamic lin' libraries (%DDs! and built using either ; or ;<<. Again, you will need to select the appropriate programming environment to support the selected language. Iava also can be used on the server to provide additional functionality for your -eb"based application. #un +icrosystems built Iava as an independent programming language. It can be implemented as an application program or as a Iava applet. A Iava application can interact with system resources and ma'e calls to e)ternal programs. A Iava applet is found embedded within a web page and cannot interact with system resources. 9egardless of your Iava implementation, an environment will be needed to support your Iava development. +icrosoft(s $isual I<< and #ymantec(s $isual ;afJ are some of the more popular tools for Iava development. ,ou will invariably need to select a scripting language to support the functionality of your application. -hether it is $:#cript or Iava#cript, you will need an editor. 4otepad, $isual :asic, and the Active1 ;ontrol Pad from +icrosoft all can support your $:#cript needs to varying degrees. 4etscape 4avigator Aold and 4otepad support Iava#cript development. If you(re wondering about connecting your application to a database, many options e)ist for database connectivity, depending on how you want to implement your application. If you(re building a Iava"based application, you will select a tool that supports Iava %atabase ;onnectivity, or I%:;. +ost of the popular Iava tools also support I%:;. +icrosoft and 4etscape also provide environments and tools for database connectivity based on their API specification. The point in this e)ample is that you could spend a lot of time and effort using a number of tools to implement a robust, -eb"based application. ;ompatibility between the tools becomes a debugging nightmare. Also, you spend a lot of time switching between the development environments, thereby diminishing your productivity. %ue to these limitations, +icrosoft created $isual Inter%ev to address the many needs for today(s -eb"based application developer. Presenting Visual InterDe$ The emphasis in creating $isual Inter%ev was to provide a tool with a comprehensive, integrated development environment. $isual Inter%ev(s creators wanted to provide a tool that enabled developers to utili=e many technologies to create and deploy dynamic, -eb"based applications. +icrosoft also wanted to emphasi=e a visual tool. +any products have been created that enable you to code HT+D or connect to a databaseH however, these tools typically haven(t focused on the ease of use for the developer. %eveloper productivity was a ma&or design goal for +icrosoft, and they have accomplished it by providing $isual Inter%ev with many wi=ards and visual tools, as well as database development features. Powerful database integration and connectivity were clearly of paramount importance for its design. $isual Inter%ev even supports developers in deploying their sites once they have been built by integrating comprehensive tools to create and maintain a web site into $isual Inter%ev. Integrated Development %nvironment $isual Inter%ev provides a robust, integrated development environment to address the many capabilities of the -eb. ,ou can integrate various technologies, li'e Active1 controls and Active #erver ;omponents, to create a powerful application. The integrated development environment enables you to use scripting languages li'e $:#cript and Iava#cript to create dynamic applications and -eb pages. ,ou can wor' on simultaneous pro&ects of different types all from within $isual Inter%ev(s %eveloper #tudio interface. In addition to $isual Inter%ev pro&ects, you also can develop $isual ;<< and $isual I<< pro&ects. Visual InterDev !eatures 4ow that you have been introduced to the features and benefits of the integrated development environment, it(s time for a brief loo' at some of the specific features of $isual Inter%ev. This discussion sets the conte)t for %ay ., in which you will get to meet $isual Inter%ev up close and personal. $isual Inter%ev includes a wide range of visual tools to augment an application developer(s productivity. HT+D editing is significantly enhanced through the use of the HT+D Dayout 5ditor and a version of the *rontPage HT+D editor. The HT+D Dayout 5ditor, introduced with the Active1 ;ontrol Pad from +icrosoft, enables you to precisely place your Active1 controls onto your web page. It also enables you to control the ) and y coordinates to ensure that the Active1 controls are displayed in the proper manner. :y using this tool, you(re able to ta'e more control of your user interface, and can ensure that the interface you build is an effective one. $isual Inter%ev also provides -,#I-,A editing through its own *rontPage ?K HT+D editor. *rontPage enables you to visually author your HT+D page. ;ontent authors can use *rontPage ?K to create files that are completely compatible with $isual Inter%ev(s version of the *rontPage 5ditor. $isual Inter%ev also provides site management tools that are very similar to those tools provided in *rontPage ?K. The #cript -i=ard is another visual tool that greatly enhances a developer(s productivity. The #cript -i=ard enables you to associate specific actions with associated Active1 control events. :y lin'ing these events and actions, the #cript -i=ard generates all of the necessary script language for you. 7nce the language is generated, you have the ability to modify and add to the code. This process can save you considerable development time by generating the routine script and enabling you to focus on the more advanced code for your application. $isual Inter%ev also includes two tools for spicing up your web pages. These tools focus on multimedia creation and management. The +icrosoft Image ;omposer and +icrosoft +usic Producer enable you to create graphical images, music, and sounds for your web site. ,ou can use the +icrosoft Image ;omposer to create engaging images for your web pages. The Image ;omposer supports the Adobe Photoshop file format as well as AI* and IPA formats. The Image ;omposer is simple to use, and you don(t have to be a graphic artist to master it. The +usic Producer enables you to create music and sound effects for your web site. ,ou pic' from over >22 pre"defined styles of music and can modify the arrangement of instruments as well as the tempo. Again, the goal of both of these products is to provide a rich and rewarding e)perience for the user. The +edia +anager enables you to manage all of your multimedia files through the use of speciali=ed folders. :y using +edia +anager, you can properly organi=e your images, sounds, video clips, and other multimedia files. 4ow consider some of the 'ey features for building robust server applications. $isual Inter%ev enables you to create dynamic web pages through the use of Active #erver Pages. The concept of Active #erver Pages was touched on earlier in the day. As a refresher, Active #erver Pages are HT+D pages that contain server"side script. The script code can be either $:#cript, Iava#cript, or some other scripting language. The Active #erver Page, or .asp file, resides on the server machine and e)ecutes before being downloaded to the browser. Active #erver ;omponents are a significant part of building distributed and powerful applications. Active #erver ;omponents are programs, %DDs, or e)ecutables (515s!, that are built using the ;omponent 7b&ect +odel (;7+! specification. $isual :asic, $isual ;<<, and $isual I<< all support the development of ;7+"based components. These programs can be called from Active #erver Pages to provide robust application processing on the server machine. *or e)ample, you might want to build an Active #erver ;omponent that uses the strength of the ;<< language to perform financial analysis and return the results to the -eb browser. ,ou also can distribute the application processing load through the use of %istributed ;7+ (%;7+!. Active #erver ;omponents provide a method for building high transaction processing capability into your application. $isual Inter%ev provides an environment that is conducive to incorporating these components into your applications. Database Integration $isual Inter%ev provides some very robust database tools. The $isual %ata Tools included with $isual Inter%ev are easy to use and significantly reduce the time and effort for adding database capability into your application. #ome of the features include the following: Data Vie# Hisual $nter<ev pro5ect window that enables you to view all of your database ob5ects including tables, views, stored procedures, and triggers. Juer) Designer A tool that enables you to visually build your #Z" database queries and test the results. Database Designer A tool that enables you to design, create, and maintain your #Z" database. Store% Proce%ure@Trigger &%itor A tool for editing stored procedures and triggers for !icrosoft #Z" #erver :.x and (racle =.x. The Luery %esigner and the %atabase %esigner employ a user interface similar to +icrosoft Access that(s very easy to use. ,ou can drag and drop ob&ects into the wor'space and automatically build your #LD 8ueries. ,ou also can use the %atabase %esigner to populate the database and modify e)isting data. 7ther database features include the following: Acti$eN Data 4b7ects# An ob5ect1based approach to accessing a database over the Web that uses Active+ #cripting. Database Design Time *ontrols#0ontrols geared toward the automatic creation of database connectivity and generation of Active #erver scripting. Database Wi2ar%s# Wi2ar%s that gui%e )ou through the creation of an (TMLH %ata-boun% form %atabase connectivity and integration is one of the best features of $isual Inter%ev. ,ou will get a chance to use these features and tools beginning with %ay @. What Is Visual InterDe$9 The -orld -ide -eb (---! has made the Internet come alive for many new users. In the initial stages, users reali=ed that they could view numerous documents on various topics from all over the world. Through the ---, people have access to a plethora of 'nowledge. 4ot only can you read about many interesting topics on the -eb, but you also can find information about your favorite products and services. 7nce you have gained this 'nowledge, you will invariably want to act on it. #ome companies have built -eb"based applications, enabling you to buy their products and services electronically over the Internet. 7ther companies enable you to fill out registration information to begin receiving certain services. The point is, applications enable the user to act on the 'nowledge they have gained. :usinesses can capitali=e on opportunities sooner by becoming closer to the customer through a virtual mar'etplace. $isual Inter%ev provides all the necessary tools to build these vital applications for the -eb. $isual Inter%ev is a comprehensive, -eb"based application development tool. $isual Inter%ev provides an integrated environment that brings together various technologies to wor' towards a common goal of building robust and dynamic applications for the -eb. $isual Inter%ev achieves this integrated development environment through the use of the %eveloper #tudio shell interface, first used in +icrosoft(s $isual ;<<. ,ou can open and wor' on $isual ;<< and $isual I<< pro&ects while simultaneously creating your $isual Inter%ev pro&ect. This feature greatly enhances productivity, especially when you(re building ;7+ and %;7+ components and incorporating these components into your $isual Inter%ev application. $isual Inter%ev enables the developer to build applications that are dynamic and interactive. ,esterday you learned about the difference between static and dynamic web pages. $isual Inter%ev enables the developer to build dynamic web pages through the use of client" and server"side script. $:#cript is the default scripting language, but Iava#cript also can be used. %atabase integration is vital to any application. $isual Inter%ev provides a rich and robust set of visual database tools to immediately enhance your productivity. $isual Inter%ev supports the ma&or 7%:;" compliant databases, both on the des'top and the server. +anaging your web site once it has been developed is a very crucial function. $isual Inter%ev provides a set of tools to view and maintain your site. These tools are similar and compatible with the site management tools found in +icrosoft *rontPage. $isual Inter%ev supports the ma&or ob&ect"based technologies that e)ist for developing -eb"based applications, including Active1 controls and Iava applets. $isual Inter%ev supports the use of third"party Active1 controls and enables you to integrate your own custom Active1 controls. $isual Inter%ev also provides %esign"time ;ontrols that enable you to set control properties when you(re designing your application and then use this functionality at runtime without the overhead of a typical Active1 control. In a nutshell, $isual Inter%ev is an e)citing new tool that significantly augments a -eb developer(s productivity. In this ne)t section, you will learn why you need to use $isual Inter%ev instead of other development tools. Wh) Visual InterDe$9 The basic premise behind the creation of $isual Inter%ev was to provide a tool that enabled developers to build dynamic and interactive applications for the -eb. 7n the first day, you read about some of the similarities and differences between client"server application development and application development for the -eb. 5ssentially, these two modes of computing were the same in that they both used the client"server model. That is, client"server and -eb applications both facilitate the client ma'ing a re8uest of the server. The main difference is the degree to which they distribute the application logic between the client and the server. *igure ..> depicts the distribution of logic for a typical client"server application. !igure #.". A typical configuration for a client-server application. -hile a client"server application distributes a mi) of presentation, application, and database logic between the client and server, -eb applications typically parcel almost all of the logic to the server. Gsing this mi), -eb applications can provide the thinnest client of all, where the only component that(s installed on the client machine is a browser. *igure ... shows the configuration for a typical -eb"based application. !igure #.#. A typical configuration for a Web-based application. 14T&: The previous architecture diagrams represent a typical configuration for both client1server and Web1based applications. Jou can distribute the presentation, application, and database logic to varying degrees between the client and the server in both computing models. This comparison is meant to show the benefit of the Web1based style of computing over client1server in terms of software distribution, version control, and administration. The benefit of -eb"based applications hinges on providing a universal client to all users that ma'e re8uests of a centrali=ed application stored on the server. This application is comprised of HT+D pages, client" and server"side script, ob&ect"based controls, and other server" side components that provide robust application processing. -ith a client"server application, you still have a client component that you have to install with every new enhancement and change to your application. -ith a -eb"based application, the browser and, hence, the client remain unchanged, and the application changes are made centrally, in one place at one time on the server. Administration, software distribution, and version control are significantly simplified under this model. A problem occurs under the -eb"based model in that the Internet doesn(t inherently support interactive sessions with the user li'e the client"server model. $isual Inter%ev supports the use of server"side components to accomplish a persistent dialogue with the user and, thus, an interactive session. $isual Inter%ev provides the tool to ta'e advantage of the new -eb" based model of computing. #ome development tools focus on supporting a single Internet technology. 7thers support several technologies for -eb"based development but don(t provide visual tools to accomplish these tas's. $isual Inter%ev e)ceeds e)isting -eb development tools by providing a way to integrate multiple technologies and supplies visual tools to greatly enhance a developer(s productivity. $isual Inter%ev also surpasses and e)tends the reach of client"server tools to the Internet and the -eb. The &ssence of Integration The American Heritage %ictionary defines the word integration in the following manner: 21. To make into a whole? unify. *. To 5oin with something else? unite.2 Truly, $isual Inter%ev unifies and unites the technologies of the -eb through its integrated development environment. ,ou can use the environment to rapidly build a robust application. ,ou have at your disposal all of the tools necessary for -eb"based application development in one integrated pac'age. In this sense, the whole really is greater than the sum of its parts. Visual InterDev Development %nvironment $isual Inter%ev provides an integrated container for a variety of visual tools. The integrated development environment is li'e a house with many rooms. 5ach of the rooms has its own specific function that contributes to the overall purpose of the house. #imilar to the rooms of a house, each function contributes to the well"being of the developer or resident. 4o single tool is more important than the other, &ust as no room is more important than another. In a typical house, you can eat, sleep, and ta'e care of your personal hygiene all under the same roof. -ith $isual Inter%ev, you can develop your web pages, connect them to a database, and deploy your web site all within the confines of the same development environment. The $isual Inter%ev development environment utili=es an implementation of the %eveloper #tudio shell that was first found in +icrosoft(s $isual ;<<. +icrosoft(s $isual I<< also incorporates this development environment. :y using the %eveloper #tudio wor'space, multiple pro&ects and tools can be supported. +icrosoft is bringing its $isual Tools family together by using the same initial shell across products. %evelopers can open many types of pro&ects created with $isual Inter%ev, $isual ;<<, and $isual I<<. The advantage of this integrated support is found in using multiple applications to provide a robust solution. ,ou can build a Iava applet using $isual I<<, incorporate the applet into your $isual Inter%ev web application, and test and debug the application all within the same environment. The same holds true for building an Active1 control using $isual ;<<. Again, integration is the 'ey word. *igure ..3 illustrates the ability to open multiple types of pro&ects from within the $isual Inter%ev integrated development environment. !igure #.$. Opening projects with isual !nter"ev. *igure ..3 shows the $isual Inter%ev *ile 7pen Pro&ect dialog window. 4otice the ability to open multiple types of pro&ects from within the environment. -hen you open your $isual Inter%ev pro&ect, you(re viewing your actual web site. The $isual Inter%ev development environment uses the 5)plorer interface to view and manage your web site files and folders. This interface simplifies the tas' of creating and maintaining your web site files and folders. Also, the interface enables you to fully organi=e the construction of your -eb"based application. The integrated development environment enables easy site creation through the use of wi=ards, and enables developers to reuse files from other sites. $isual Inter%ev enables you to easily import e)isting files into your web site structure. The 5)plorer interface enables you to accomplish this tas' through a point"and"clic' metaphor, &ust as you copy and paste files and folders on your P;. *igure ..E shows a $isual Inter%ev pro&ect using *ile $iew. !igure #.4. A typical isual !nter"ev project. The *ile $iew is the default view for a typical $isual Inter%ev pro&ect. 4otice the tabs at the bottom of the pane on the left"hand side of the wor'space. *ile $iew enables you to see the structure of your web site including files and folders. This view displays the entire contents of your site, including HT+D pages, images, controls, applets, and other files. The pane to the right of this wor'space displays the ob&ect that is selected based upon its file type. *or e)ample, if you selected an HT+D page from the list on the left, the HT+D code would be displayed in the window on the right. %ata$iew is the other tab located ne)t to the *ile$iew tab. This view shows all of your database ob&ects, including tables, views, stored procedures, and triggers. The %ata $iew provides a direct connection to your 7%:; datasource to enable remote configuration and maintenance as well as interaction. *igure ..B demonstrates the %ata $iew showing a sample Access database. !igure #.&. The "ata iew. 14T&: The <ata Hiew only appears as an option for web pro5ects after you have inserted a database connection. The <ata Hiew also is displayed for <atabase ,ro5ects. Visual SourceSafe Integration $isual Inter%ev supports integration with $isual #ource#afe to provide version control cap"abilities li'e chec'"in0chec'"out. #imilar to any application development effort, source code control becomes a big issue when you(re building a site with multiple team members. %evelopers can chec' out their portion of the site, ma'e the appropriate changes, and send the file bac' to the server to be incorporated with the other developers( files. 5ffective team development is covered in more detail on %ay >?, -or'ing 5ffectively in Teams with $isual #ource#afe. 'rowser Integration Another feature of $isual Inter%ev is the integration of a browser within the development environment. $isual Inter%ev includes an implementation of the +icrosoft Internet 5)plorer 3.2 browser. This implementation supports all of the same features of the commercial version of Internet 5)plorer, including Iava applets, Active1 controls, Active1 documents, $:#cript and Iava#cript, style sheets, and HT+D 3.) features such as frames and tables. :y using the Preview in :rowser feature, you don(t have to use one tool to build the application and then open up your browser to view it. -ith $isual Inter%ev, you can build your -eb"based application and view the results all from within one environment. This feature adds to the speed with which a developer can create and update applications and web sites. ,ou do have the capability to use the :rowse -ith function to view your web site from within the browser(s native window. *or e)ample, you could configure Internet 5)plorer or 4etscape 4avigator and view the site from within the production browser environment. ,ou probably will want to use this feature during final testing of your web site. If you(re deploying your site for use with the 4etscape 4avigator browser, you have to use this feature. ,ou can use either of these features by selecting an HT+D file and right"clic'ing the mouse to display the shortcut menu. *igure ..M shows the Preview in :rowser and :rowse -ith menu options on the shortcut menu for an HT+D file. !igure #.(. #rowser viewing options. Ta>ing a *loser Loo> at the *om!onents The previous section discussed how $isual Inter%ev provides an integrated development environment from which to wor'. ,ou saw the basic $isual Inter%ev wor'space and the different views that are available. In this section, you get a guided tour through each of the features and components that ma'e up $isual Inter%ev. Visual InterDev %ditors $isual Inter%ev provides several visual editors for designing and developing your HT+D web pages. The following list outlines those that are available: T!" #ource %ditor 'ront,age %ditor for Hisual $nter<ev T!" "ayout %ditor (b5ect %ditor (TML Source &%itor Gsing this editor, you can create and edit your HT+D code, which is color"coded, providing a visually appealing synta). ,ou can incorporate many ob&ects and controls, such as HT+D layouts and controls, Active1 controls, and %esign"time Active1 controls. The editor also supports the use of script with your HT+D web page. *igure ..K highlights standard HT+D code using the HT+D #ource 5ditor. !igure #.). The $T%& Source 'ditor. 0rontPage &%itor for Visual InterDe$ This editor is an implementation of the +icrosoft *rontPage 5ditor created for $isual Inter%ev. This editor is completely compatible with the full version of +icrosoft *rontPage and provides a visual tool for developing HT+D web pages. ,ou may already be familiar with +icrosoft *rontPage. The *rontPage 5ditor uses a -,#I-,A approach to develop HT+D code. This approach enables you to add HT+D features to your web page through a graphical, point"and"clic' metaphor. *or e)ample, to add a table, you select the Insert Table menu item from the Table menu and then visually set the parameters, such as number of rows and columns. -ith the *rontPage 5ditor, you can visually wor' with ob&ects instead of the underlying HT+D to construct your web pages. This method can substantially save development time. 7nce you have constructed a web page using the graphical editor, you can access and manipulate the generated HT+D code and add your own custom HT+D. The *rontPage 5ditor also supports the incorporation of plug"ins, Active1 controls, and Iava applets. *igure ..@ highlights the -,#I-,A features of the *rontPage 5ditor for $isual Inter%ev. !igure #.*. The (rontPage 'ditor for isual !nter"ev. (TML La)out &%itor The HT+D Dayout 5ditor is the same editor that was first included with the Active1 ;ontrol Pad from +icrosoft. This editor provides a way to accurately position all of your Active1 controls on your web page. The interface is very similar to tools li'e $isual :asic, which enable you to position your ob&ects on forms. -ith this layout editor, you can drag and drop controls onto the layout and establish their properties and e)act position within the web page. -hen the form is displayed by the browser at runtime, the controls are positioned at the e)act coordinates that were specified at design time. The toolbo) enables you to add and delete controls. ,ou also can use the #cript -i=ard to automatically add scripting code for use with your controls. *igure ..? displays the HT+D Dayout 5ditor. !igure #.+. The $T%& &ayout 'ditor. 4b7ect &%itor The 7b&ect 5ditor enables you to establish the properties for your Active1 and %esign"time Active1 controls as well as Iava applets and 4etscape plug"ins. The 7b&ect 5ditor is activated after you insert an ob&ect into your HT+D source code. *or e)ample, to position an Active1 control on your web page, you would right"clic' the mouse where you wanted the ob&ect to be placed within your HT+D code. 14T&: Jou must click between the <HTML> and </HTML> tags that signify the beginning and ending of your code. ,ou can then choose between regular and %esign"time controls. 7nce you have chosen a control, the 7b&ect 5ditor is displayed, enabling you to set the properties for the given control. *igure ..>2 e)hibits the 7b&ect 5ditor for a typical Active1 control. !igure #.",. The Object 'ditor. As you can see, there are several editors that you can choose, based on the tas' that you(re trying to accomplish. These editors are covered in"depth later in the wee'. ,ou also will get a chance to use each of these editors to e)perience their features during the first wee'. Active- .ontrols and /ava Applets $isual Inter%ev includes and supports the use of Active1 controls. Active1 controls are the ne)t generation of 7D5 controls, .7;1 files. These controls use less overhead and memory and are perfect for transporting over the Internet. These controls also can be used with other client"server development tools, li'e $isual :asic and $isual ;< <. Active1 controls e)tend the reach of HT+D controls and enable you to create effective user interfaces. Gsing the editors mentioned in the previous section, you can visually set the properties for the Active1 control. $isual Inter%ev also supports the use of Iava applets and 4etscape plug"ins. ,ou can wor' within the frame of either of these controls to visually establish their properties. Design01ime Active- .ontrols $isual Inter%ev uses %esign"time Active1 controls to provide similar functionality to regular Active1 controls without the processing overhead. %esign"time Active1 controls enable you to visually set properties for the control at design time. The %esign"time control then generates HT+D and scripting code based on the properties that you select. 9egular Active1 controls differ in that they include a run"time component that e)ecutes within the conte)t of the browser. %esign"time Active1 controls have no run"time component. Their script is processed on the server, and the HT+D and results are returned to the client. $isual Inter%ev provides many %esign"time controls, including some very powerful controls for building database connectivity. ,ou can also build your own design"time controls with tools such as $isual :asic and $isual ;<<.