Macromedia Dreamweaver MX 2004 - ASP Ontwerpen van webapplicaties met ASP en Access
Versie 1.2 - maart 2005 Macromedia, Dreamweaver, UltraDev, Fireworks, Flash, Contribute en FreeHand zijn handelsmerken of gedeponeerde handelsmerken van Macromedia, Inc. in de Verenigde Staten en/of andere landen. Alle overige handelsmerken en merknamen zijn eigendom van hun respectieve eigenaars. Speciale dank aan Lieve en Guy voor hun meer dan gewaardeerde medewerking. 1
Verhaert, Patrick – Macromedia Dreamweaver MX 2004 – ASP / Patrick Verhaert; Geel: Campinia Media vzw, 2004; 428 p; index; 25,5 cm; gelijmd. ISBN: 90.356.1176.4; NUGI 854; UDC 681.3.06; 2de druk Wettelijk depot België: D/2004/3941/3 Campinia Media vzw Kleinhoefstraat 4 B – 2440 – GEEL (Belgium) Tel.: (+32) 014/59 09 59 Fax: (+32) 014/59 03 44 e-Mail:
URL: <www.campiniamedia.be> Copyright 2004:
No part of this book may be reproduced in any form, by print, photoprint, microfilm or any other means without written permission of the publisher. Niets uit deze uitgave mag worden verveelvoudigd en/of openbaar gemaakt door middel van druk, fotokopie, print, microfilm of op welke andere wijze ook, zonder voorafgaande schriftelijke toestemming van de uitgever.
Inhoud 1 Introductie. ..........................................................................................................13 1.1 Historiek...................................................................................................................13 1.2 Voorkennis. ..............................................................................................................14 1.3 Conventies...............................................................................................................14 1.4 Systeemvereisten. ...................................................................................................14 1.4.1 Microsoft-Windows........................................................................................14 1.4.2 Mac-OS. ........................................................................................................15 1.5 Lesmateriaal bij dit handboek. .................................................................................15 1.5.1 Lesmateriaal installeren op PC. ....................................................................15 1.5.2 Lesmateriaal installeren op Macintosh..........................................................15 1.6 De help-functie.........................................................................................................16 1.7 Extensies. ................................................................................................................16
2 Statische en dynamische websites...................................................................17 2.1 Statische vs. dynamische websites. ........................................................................18 2.1.1 Statische webpagina's. .................................................................................18 2.1.2 Statische website. .........................................................................................18 2.1.3 Dynamische webpagina's. ............................................................................18 2.1.4 Dynamische website of Webapplicatie..........................................................19 2.2 Ondersteunde servermodellen in Dreamweaver MX 2004......................................19 2.2.1 Active Server Pages (ASP): ..........................................................................19 2.2.2 ASP.NET:.......................................................................................................20 2.2.3 Java Server Pages (JSP):.............................................................................20 2.2.4 ColdFusion MX:.............................................................................................20 2.2.5 PHP:..............................................................................................................20
3 IIS en PWS. ..........................................................................................................21 3.1 Externe webserver (live server). ..............................................................................21 3.2 Testserver. ...............................................................................................................23 3.2.1 Verborgen map of subdomein op de live server............................................24 3.2.2 Lokale testserver. ..........................................................................................24 3.2.3 Externe testserver. ........................................................................................26 3.3 IIS of PWS installeren..............................................................................................27 3.3.1 IIS installeren op Windows 2000 Professional. .............................................27 3.3.2 IIS installeren op Windows XP Professional. ................................................29 3.3.3 PWS installeren op Windows 98. ..................................................................30 3.3.4 Overige Windowssystemen...........................................................................31 3.4 Testserver raadplegen vanuit een browser. .............................................................31 3.4.1 Vanaf een browser op de testserver..............................................................32 3.4.2 Vanaf een browser op een ander toestel binnen het netwerk. ......................32
4 Virtuele mappen onder IIS en PWS. ..................................................................35 4.1 Map binnen de wwwroot delen via het web. ............................................................36 4.2 Map buiten de wwwroot delen via het web. .............................................................37 4.3 Personal Web Manager. ..........................................................................................40 4.4 Internet Information Services...................................................................................43
Inhoud - 3
5 Connecteren op een externe testserver............................................................45 5.1 Connectie via FTP....................................................................................................45 5.2 Connectie via het netwerk. ......................................................................................51 5.2.1 Connecteren vanaf een Windowsmachine....................................................52 5.2.2 Connecteren vanaf Mac OSX. ......................................................................54
6 Dynamische website definiëren. .......................................................................57 6.1 Virtuele map toevoegen aan de testserver. .............................................................57 6.2 Website definiëren. ..................................................................................................58 6.2.1 Local info.......................................................................................................58 6.2.2 Remote info...................................................................................................59 6.2.3 Testing Server. ..............................................................................................60 6.2.4 URL Prefix testen. .........................................................................................61 6.2.5 Connecteren met de testserver. ....................................................................62 6.3 Nieuwe ASP-pagina aanmaken in Dreamweaver. ...................................................63 6.4 Live Data view..........................................................................................................65 6.4.1 Preview in Browser........................................................................................65 6.4.2 Rechtstreeks openen in een browser............................................................65 6.4.3 Live Data view. ..............................................................................................66
7 Initiatie tot ASP - VBScript. ................................................................................69 7.1 ASP-delimiters. ........................................................................................................71 7.1.1 Opdracht 1 ....................................................................................................72 7.2 Commentaar. ...........................................................................................................73 7.3 Variabelen................................................................................................................73 7.3.1 Variant. ..........................................................................................................73 7.3.2 Variabelen dimensioneren. ...........................................................................74 7.3.3 Variabelen in Dreamweaver. .........................................................................77 7.3.4 Soorten variabelen. .......................................................................................77 7.4 Strings......................................................................................................................78 7.5 Operatoren...............................................................................................................82 7.5.1 Rekenkundige operatoren.............................................................................82 7.5.2 Vergelijkende operatoren. .............................................................................83 7.5.3 Logische operatoren. ....................................................................................83 7.6 Voorwaardelijke instructies. .....................................................................................84 7.6.1 If-Then-Else...................................................................................................84 7.6.2 Opdracht 2. ...................................................................................................88 7.6.3 Opdracht 3. ...................................................................................................89 7.6.4 Select-Case...................................................................................................90 7.7 Lussen. ....................................................................................................................91 7.7.1 For-Next. .......................................................................................................91 7.7.2 While-Wend...................................................................................................93 7.7.3 Do-While. ......................................................................................................95 7.7.4 For-Each-In. ..................................................................................................96 7.8 Datum en tijd............................................................................................................96 7.8.1 Datum- en tijdformaten..................................................................................97 7.8.2 Datum splitsen in dag, maand en jaar...........................................................98 7.8.3 Tijd splitsen in uren, minuten en seconden. ..................................................99 7.8.4 Local Identifier ID (LCID).............................................................................100 7.8.5 Opdracht 4. .................................................................................................102 4 - Dreamweaver MX 2004 - ASP
7.9 Procedures. ...........................................................................................................104 7.9.1 Subroutines. ................................................................................................104 7.9.2 Functies.......................................................................................................106 7.9.3 Includes.......................................................................................................108 7.10 datatype converteren. ..........................................................................................109 7.11 Naamgeving. ........................................................................................................111 7.12 Gereserveerde woorden. .....................................................................................111 7.13 Bronnen. ..............................................................................................................112
8 Het ASP-objectmodel........................................................................................113 8.1 Formulieren............................................................................................................114 8.2 Het Request-object. ...............................................................................................115 8.2.1 Request.QueryString...................................................................................116 8.2.2 Opdracht 1...................................................................................................118 8.2.3 Request.Form. ............................................................................................125 8.2.4 Opdracht 2. .................................................................................................126 8.2.5 Request.Cookies.........................................................................................130 8.2.6 Request.ServerVariables. ...........................................................................130 8.2.7 Request.ClientCertificate. ...........................................................................131 8.2.8 Prioriteiten. ..................................................................................................131 8.3 Het Response-object. ............................................................................................132 8.3.1 Response.Write...........................................................................................132 8.3.2 Response.Redirect......................................................................................132 8.3.3 Opdracht 3. .................................................................................................133 8.3.4 Response.Buffer..........................................................................................134 8.3.5 Response.End.............................................................................................135 8.3.6 Response.Cookies. .....................................................................................136 8.4 Het Session-object.................................................................................................139 8.4.1 Session.SessionID en Session.Timeout. ....................................................140 8.4.2 Sessievariabelen aanmaken. ......................................................................141 8.4.3 Waarde van een Sessievariabele uitlezen. .................................................142 8.4.4 Sessievariabelen wissen.............................................................................142 8.4.5 Een sessie beëindigen. ...............................................................................142 8.4.6 Login met sessievariabelen.........................................................................142 8.5 Het Application-object. ...........................................................................................147 8.5.1 Toepassingsvariabelen aanmaken..............................................................147 8.5.2 Waarde van een toepassingsvariabele uitlezen..........................................147 8.5.3 Toepassingsvariabelen wissen....................................................................147 8.6 Het global.asa bestand. .........................................................................................148 8.7 Het Server-object...................................................................................................152 8.7.1 Server.MapPath. .........................................................................................152 8.7.2 Server.CreateObject....................................................................................152 8.8 Variabelen: een vergelijkend overzicht. .................................................................153 8.9 Variabelen in het Bindings palet. ...........................................................................154 8.10 Overige collecties, methoden en eigenschappen. ...............................................155 8.11 Bronnen. ..............................................................................................................155
Inhoud - 5
9 Server behaviors...............................................................................................157 9.1 Een Server Behavior zonder parameters aanmaken.............................................158 9.2 Een Server Behavior met parameters aanmaken..................................................160 9.3 Toepassing 1..........................................................................................................163 9.4 Een Server Behavior bewerken en/of wissen. .......................................................167 9.5 Uw persoonlijke Server Behavior verspreiden.......................................................167 9.5.1 BewaarCookie.mxi. .....................................................................................170 9.5.2 Bewaar cookie.htm......................................................................................172 9.5.3 Bewaar cookie.edml....................................................................................172 9.5.4 Bewaar cookie_block1.edml. ......................................................................173 9.5.5 BewaarCookie.mxp-bestand aanmaken. ....................................................174 9.5.6 BewaarCookie.mxp installeren....................................................................174 9.5.7 BewaarCookie.mxp verspreiden. ................................................................176 9.5.8 Samenvatting. .............................................................................................176 9.6 Extra Server Behaviors downloaden en installeren. ..............................................177 9.7 Bronnen. ................................................................................................................177
10 Microsoft Access. ...........................................................................................179 10.1 Tabellen. ..............................................................................................................180 10.2 Primaire sleutel. ...................................................................................................180 10.3 Database normalisatie. ........................................................................................181 10.4 Externe of secundaire sleutel. .............................................................................182 10.5 Referentiële integriteit..........................................................................................182 10.6 Kolommen indexeren...........................................................................................183 10.7 Praktische realisatie.............................................................................................183 10.7.1 Auteurstabel toevoegen. ...........................................................................186 10.7.2 Gegevens importeren................................................................................188 10.7.3 Relaties leggen tussen tblBoeken en tblAuteurs.......................................191 10.7.4 Logintabel toevoegen................................................................................193 10.7.5 Indexen toevoegen....................................................................................194 10.8 Database comprimeren. ......................................................................................194 10.9 Uw database beveiligen.......................................................................................195 10.9.1 Paswoord toekennen. ...............................................................................196 10.9.2 Paswoord wissen. .....................................................................................196 10.10 Besluit. ...............................................................................................................197 10.11 Bronnen. ............................................................................................................197
11 Een databasekoppeling maken......................................................................199 11.1 Virtuele map toevoegen aan de testserver. .........................................................199 11.2 Nieuwe website definiëren in Dreamweaver. .......................................................200 11.3 MDAC. .................................................................................................................203 11.3.1 MDAC-versie controleren. .........................................................................204 11.3.2 ADO-versie controleren via ASP................................................................204 11.4 Soorten databasekoppelingen. ............................................................................205 11.5 Database beveiligen tegen downloaden. .............................................................206 11.6 Koppeling via ODBC met DSN. ...........................................................................208 11.6.1 U gebruikt een lokale testserver. ...............................................................208 11.6.2 U gebruikt een externe testserver. ............................................................210 11.6.3 Databasekoppeling op de live server.........................................................211 11.7 Koppeling via ODBC zonder DSN (DSN-less connectie). ...................................212 6 - Dreamweaver MX 2004 - ASP
11.7.1 Connectiestring op de testserver (lokaal of extern) ..................................213 11.7.2 Databasekoppeling op de live server. .......................................................213 11.8 Koppeling via OLE DB. ........................................................................................214 11.8.1 Connectiestring op de testserver (lokaal of extern) ..................................215 11.8.2 Databasekoppeling op de live server. .......................................................216 11.9 Besluit. .................................................................................................................216 11.10 Bronnen. ............................................................................................................218
12 SQL...................................................................................................................219 12.1 Over de database. ...............................................................................................220 12.2 Alle records uit een tabel tonen (SELECT). .........................................................220 12.2.1 SQL-instructie. ..........................................................................................220 12.2.2 In Dreamweaver. .......................................................................................220 12.3 Records sorteren (ORDER BY). ..........................................................................224 12.3.1 SQL-instructie. ..........................................................................................224 12.3.2 In Dreamweaver. .......................................................................................225 12.4 Specifieke kolommen uit een tabel selecteren. ...................................................227 12.4.1 SQL-instructie. ..........................................................................................227 12.4.2 In Dreamweaver. .......................................................................................227 12.5 Een recordset filteren op één criterium (WHERE). ..............................................228 12.5.1 SQL-instructie. ..........................................................................................228 12.5.2 In Dreamweaver. .......................................................................................229 12.6 Een recordset filteren via een zoekopdracht. ......................................................230 12.7 Een recordset filteren op meerdere criteria. ........................................................232 12.8 Gegevens aan de database toevoegen (INSERT). .............................................233 12.8.1 SQL-instructie. ..........................................................................................233 12.8.2 In Dreamweaver. .......................................................................................234 12.9 Gegevens aanpassen (UPDATE). .......................................................................236 12.9.1 SQL-instructie. ..........................................................................................236 12.9.2 In Dreamweaver. .......................................................................................236 12.10 Gegevens uit de database verwijderen (DELETE). ...........................................239 12.10.1 SQL-instructie. ........................................................................................239 12.10.2 In Dreamweaver. .....................................................................................239 12.11 Gegevens uit twee tabellen samenvoegen (JOIN). ...........................................241 12.11.1 SQL-instructie..........................................................................................241 12.11.2 In Dreamweaver. .....................................................................................242 12.11.3 Query's in Access. ...................................................................................243 12.11.4 In Dreamweaver. .....................................................................................245 12.12 Besluit. ...............................................................................................................246 12.13 Bronnen. ............................................................................................................246
13 Microsoft Access gegevenstypes. ................................................................249 13.1 Datumveld............................................................................................................250 13.1.1 Datum toevoegen......................................................................................250 13.1.2 Datum formatteren. ...................................................................................253 13.2 Ja/nee-veld. .........................................................................................................254 13.3 Memoveld. ...........................................................................................................256 13.4 Getallen. ..............................................................................................................259 13.5 Besluit. .................................................................................................................261
Inhoud - 7
14 Webapplicatie: boekengids............................................................................263 14.1 Een databasekoppeling maken. ..........................................................................263 14.2 De database boekengids.mdb. ............................................................................265 14.3 De templates........................................................................................................266 14.4 Het global.asa bestand. .......................................................................................266 14.5 Live Data view......................................................................................................268 14.6 Het publieke gedeelte van de website. ................................................................268 14.6.1 Overzichtspagina boeken (default.asp).....................................................268 14.6.2 Detailpagina boeken (detail.asp)...............................................................278 14.7 Het administratieve gedeelte van de website. .....................................................284 14.7.1 Overzichtspagina (default.asp). ................................................................285 14.7.2 Een nieuwe auteur toevoegen (auteurs/default.asp). ...............................285 14.7.3 Een auteur bewerken (auteurs/bewerk.asp). ............................................288 14.7.4 Een auteur wissen (auteurs/wis.asp). .......................................................290 14.7.5 Een nieuw boek toevoegen (boeken/default.asp). ....................................292 14.7.6 Een boek bewerken (boeken/bewerk.asp)................................................296 14.7.7 Een boek wissen (boeken/wis.asp)...........................................................299 14.7.8 De loginpagina (admin/login.asp)..............................................................301 14.7.9 Pagina's beveiligen. ..................................................................................303 14.8 Logout (logout.asp)..............................................................................................304 14.9 Extra functionaliteit toevoegen.............................................................................305
15 Mailcomponenten. ..........................................................................................307 15.1 Virtuele map toevoegen aan de testserver. .........................................................308 15.2 Nieuwe website definiëren in Dreamweaver........................................................308 15.3 SMTP-Server. ......................................................................................................311 15.3.1 Open relay.................................................................................................312 15.3.2 Relay. ........................................................................................................312 15.3.3 Authenticated Relay. .................................................................................314 15.3.4 SMTP-server van uw Internet provider......................................................315 15.3.5 Besluit. ......................................................................................................317 15.4 Geïnstalleerde mailcomponenten controleren. ....................................................318 15.5 JMail. ...................................................................................................................319 15.5.1 Instantie.....................................................................................................319 15.5.2 Eenvoudig mailscript. ................................................................................320 15.5.3 CC en BCC. ..............................................................................................321 15.5.4 Foutboodschap weergeven.......................................................................321 15.5.5 Prioriteit toekennen. ..................................................................................322 15.5.6 Opdracht 1. ...............................................................................................322 15.5.7 Bijlage toevoegen......................................................................................323 15.5.8 Tekst - HTML.............................................................................................323 15.5.9 Verificatie op de SMTP-server...................................................................326 15.5.10 Opdracht 2. .............................................................................................326 15.6 Gegevens verzenden via een formulier. ..............................................................326 15.7 ASPEmail.............................................................................................................327 15.7.1 Instantie.....................................................................................................327 15.7.2 Eenvoudig mailscript. ................................................................................328 15.7.3 CC en BCC. ..............................................................................................328 15.7.4 Foutboodschap weergeven.......................................................................328 15.7.5 Prioriteit toekennen. ..................................................................................329 8 - Dreamweaver MX 2004 - ASP
15.7.6 Bijlage toevoegen......................................................................................329 15.7.7 Tekst - HTML.............................................................................................329 15.7.8 Verificatie op de SMTP-server...................................................................329 15.7.9 Opdracht 3. ...............................................................................................330 15.8 CDONTS..............................................................................................................330 15.8.1 Instantie.....................................................................................................330 15.8.2 Eenvoudig mailscript. ................................................................................330 15.8.3 CC en BCC. ..............................................................................................331 15.8.4 Foutboodschap weergeven.......................................................................331 15.8.5 Prioriteit toekennen. ..................................................................................331 15.8.6 Bijlage toevoegen......................................................................................331 15.8.7 Tekst - HTML.............................................................................................332 15.8.8 Verificatie op de SMTP-server...................................................................332 15.8.9 Opdracht 4. ...............................................................................................332 15.9 E-mail snippets. ...................................................................................................332 15.10 Formprocessor...................................................................................................333 15.11 Uw lokale SMTP-server. ....................................................................................336 15.12 Bronnen. ............................................................................................................338
16 Webapplicatie: mailinglijst. ............................................................................339 16.1 De databasekoppeling aanpassen. .....................................................................340 16.2 De database mailing.mdb. ...................................................................................340 16.3 De templates........................................................................................................341 16.4 Het include bestand (mailscript.asp)....................................................................341 16.5 Het publieke gedeelte van de site........................................................................343 16.5.1 Registratie nieuwe gebruiker (subscribe.asp). ..........................................344 16.5.2 Verzend registratie (subscribeZend.asp). .................................................345 16.5.3 Bevestiging nieuwe gebruiker (subscribeBevestig.asp)............................348 16.5.4 Gebruiker uitschrijven (unsubscribe.asp)..................................................349 16.5.5 Gebruiker wissen uit de database (unsubscribeWis.asp). ........................350 16.6 Het administratieve gedeelte van de site.............................................................351 16.6.1 Overzichtspagina (admin/default.asp).......................................................351 16.6.2 Overzicht actieve gebruikers (admin/actief.asp). ......................................352 16.6.3 Gebruikers wissen (admin/wis.asp). .........................................................355 16.6.4 Overzicht niet-actieve gebruikers (admin/nietActief.asp). .........................355 16.6.5 Mailing aanmaken (admin/mailing.asp).....................................................356 16.6.6 Mailing verzenden (admin/zenden.asp). ...................................................356 16.6.7 Loginpagina (admin/login.asp). .................................................................360 16.6.8 Pagina's beveiligen. ..................................................................................361 16.6.9 Logoutpagina (admin/logout.asp)..............................................................362 16.7 Mogelijke uitbreidingen. .......................................................................................362
Inhoud - 9
17 Webapplicatie: opleidingscentrum................................................................363 17.1 Virtuele map toevoegen aan de testserver. .........................................................363 17.2 Nieuwe website definiëren in Dreamweaver........................................................364 17.3 Een databasekoppeling maken. ..........................................................................367 17.4 De database opleiding.mdb. ................................................................................368 17.5 De templates........................................................................................................368 17.6 De helppagina......................................................................................................369 17.7 Opleidingen..........................................................................................................369 17.7.1 Overzichtspagina opleidingen (opleiding/default.asp)...............................370 17.7.2 Detailpagina opleidingen (opleiding/detail.asp).........................................380 17.7.3 Inschrijvingsformulier (opleiding/inschrijven.asp)......................................384 17.7.4 Formulier verzenden (opleiding/zendEmail.asp).......................................386 17.8 Logout..................................................................................................................387 17.9 Docenten. ............................................................................................................388 17.9.1 Loginpagina voor docenten (docent/login.asp). ........................................388 17.9.2 Cookie bewaren (docent/setCookie.asp). .................................................391 17.9.3 Persoonlijke gegevens van een docent (docent/default.asp). ..................393 17.9.4 Logingegevens verzenden via e-mail (docent/zendPaswoord.asp)..........397 17.10 Personeel...........................................................................................................399 17.10.1 Loginpagina voor personeelsleden (personeel/login.asp).......................400 17.10.2 Overzichtpagina voor personeelsleden (personeel/default.asp). ............402 17.10.3 Overzichtpagina opleidingen (personeel/opleidingen/default.asp)..........405 17.10.4 Een opleiding bewerken of wissen (personeel/opleidingen/bewerk.asp).406 17.10.5 Een nieuwe opleiding toevoegen (personeel/opleidingen/nieuw.asp).....411 17.10.6 Een docent bewerken of wissen (personeel/docent/bewerk.asp). ..........413 17.10.7 Een nieuwe docent toevoegen (personeel/docent/nieuw.asp)................417 17.11 Opdracht. ...........................................................................................................418
Index......................................................................................................................421
10 - Dreamweaver MX 2004 - ASP