Professional Documents
Culture Documents
HCM
Email: ledduy@ieee.org
Chng 1
Email: ledduy@ieee.org
Email: ledduy@ieee.org
Available Network
Address
# of
Networks
# of Hosts
Default
Subnet
1 - 126
126
16.7 million
255.0.0.0
128.xxx 191.xxx
16.384
65.536
255.255.0.0
192.xxx.xxx
223.xxx.xxx
2.097.152
256
255.255.255.0
Email: ledduy@ieee.org
Email: ledduy@ieee.org
truy cp vo mt trang web, bn cn phi bit a ch (URL Uniform Resource Locator) ca trang web . V d, truy cp vo
trang
web
ca
cng
ty
Microsoft,
bn
g
vo:
http://www.microsoft.com/ms.htm. Do dch v ny s dng giao thc
HTTP (Hypertext Transfer Protocol) nn mi a ch trang web lun
c bt u l http://
Email: ledduy@ieee.org
Email: ledduy@ieee.org
2.2. Th in t - Email
2.4. Tn gu - Chat
Dch v tn gu cho php ngi dng c th trao i trc tuyn
vi nhau qua mng Internet. Cch thng dng nht l trao i bng
vn bn. Nu ng truyn tt, bn c th tr chuyn tng t nh
ni chuyn in thoi.
10
Email: ledduy@ieee.org
Email: ledduy@ieee.org
Google (http://www.google.com)
Yahoo Messenger
Cc chng trnh ny khng nhng h tr tn gu qua vn bn
thng thng m cn h tr tr chuyn bng m thanh (voice chat)
v hnh nh (webcam)
Yahoo (http://www.yahoo.com)
11
12
Email: ledduy@ieee.org
Email: ledduy@ieee.org
ZDNet (http://www.zdnet.com/downloads/)
Codeguru (http://www.codeguru.com)
CNet (http://download.cnet.com)
CodeProject (http://www.codeproject.com)
13
14
Email: ledduy@ieee.org
Email: ledduy@ieee.org
MSDN (http://msdn.microsoft.com)
ProgrammersHeaven (http://www.programmersheaven.com)
Amazon (http://www.amazon.com)
15
16
Email: ledduy@ieee.org
Email: ledduy@ieee.org
eBay (http://www.ebay.com)
17
18
Email: ledduy@ieee.org
Email: ledduy@ieee.org
19
Email: ledduy@ieee.org
Email: ledduy@ieee.org
5. MT S CU HI THNG GP
5.1. Cch lu mt trang web t Internet
Cch 1: Nu bn dng trnh duyt Internet Explorer t 5.0 tr ln
hy chn chc nng Favorites/Add to Favorites sau nh du
chn vo Make available offline. Khi ton b trang Web cng cc
tp tin i km s c ti v. Ln sau, bn ch cn vo li Favorites
v chn trang ti v.
21
22
Email: ledduy@ieee.org
Email: ledduy@ieee.org
open ftp.ets.org
cd /pub/toefl
mode binary
uuencode
get 993007listb.pdf
quit
23
24
Email: ledduy@ieee.org
Email: ledduy@ieee.org
25
26
Email: ledduy@ieee.org
Email: ledduy@ieee.org
CU HI
1.
2.
3.
4.
5.
6.
27
28
Email: ledduy@ieee.org
Email: ledduy@ieee.org
THC HNH
1.1. Kt ni
ng in thoi.
ng k dch v vi cc nh cung cp dch v Internet bit
c s in thoi truy cp, tn ng nhp v mt khu. Ti
Vit Nam, bn c th ng k vi cc nh cung cp sau VDC,
FPT, SaiGonNet, . Sau khi ng k xong, bn s c nhn
mt s tn ng nhp, mt khu v s in thoi m bn s
quay s t my ca bn vo my ch ca nh cung cp dch
v.
29
Email: ledduy@ieee.org
Email: ledduy@ieee.org
31
32
Email: ledduy@ieee.org
Email: ledduy@ieee.org
33
34
Email: ledduy@ieee.org
Email: ledduy@ieee.org
5. CHIA S NG KT NI INTERNET
http://greetings.yahoo.com
http://www.geraldstevens.com/
http://www.1800flowers.com/
http://www.123greetings.com/
http://www.vnn.vn/ecards/
http://www.fpt.vn/Postcard/main.asp
Ci t mt phn mm h tr v d nh WinGate
(http://www.wingate.com) ngay ti my c gn modem, kt ni vi
Internet.
http://www.confidantvcd.com
http://vnexpress.net/
http://www.vnn.vn/
http://www.vdc.com.vn/
http://media.vdc.com.vn/
http://www.nhandan.org.vn/
http://www.sggp.org.vn/
http://www.laodong.com.vn/
http://www.nld.com.vn/
http://www.tuoitre.com.vn
http://website.fptnet.com.vn/
35
36
Email: ledduy@ieee.org
Email: ledduy@ieee.org
Chng 2
THIT LP WEBSITE
1. CI T WEBSERVER
WebServer l chng trnh cung cp dch v www. Mt
webserver c th phc v cho nhiu website. Port mc nh cho dch
v web l 80.
C nhiu phn mm h tr webserver. Trn mi trng ca
Microsoft, thng dng nht vn l IIS (Internet Information Server)
vi cc phin bn chy trn h iu hnh WindowsNT 4.0 v
Windows 2000. Ngoi ra cc my s dng h iu hnh Win9x,
Microsoft cng h tr ci t webserver thng qua phn mm PWS
(Personal Web Server).
37
38
Email: ledduy@ieee.org
Email: ledduy@ieee.org
39
40
Email: ledduy@ieee.org
Email: ledduy@ieee.org
41
42
Email: ledduy@ieee.org
Email: ledduy@ieee.org
2. CU HNH WEBSERVER
2.1. Cc thng s chnh
Cc thng s mc nh chnh cho webserver l tn m t website
(description), a ch IP v port gn cho website. Port mc nh cho
website l 80. Nu bn s dng mt port khc, v d nh port 81 cho
website, bn phi ghi r trong ng dn URL. V d:
http://www.visc-network.com:81/ . Ngoi ra, cn c cc thng s lin
quan n s lng cc kt ni ng thi (connections), n nh
dng v ni lu tr tp tin nht k (log file) ghi li qu trnh truy cp
website.
IIS mc nh thit lp th mc C:\InetPub\wwwroot l home
directory cho website c tn l Default WebSite.
Hnh 2.7 - Mn hnh thit lp cc thng s cho website
43
44
Email: ledduy@ieee.org
Email: ledduy@ieee.org
Alias
(Home
Directory)
Scripts
URL Path
http://www.isedu.hcmuns.edu.vn
C:\InetPub\wwwroot\
http://www.isScripts
edu.hcmuns.edu.vn/Scripts/
D:\WebForum
Forum
http://www.isedu.hcmuns.edu.vn/Forum/
Trong Internet Services Manager, cc biu tng tng trng
cho th mc o s khc vi cc biu tng tng trng cho th
mc thc trong hin th cy th mc ca mt website.
45
Email: ledduy@ieee.org
Email: ledduy@ieee.org
47
48
Email: ledduy@ieee.org
Email: ledduy@ieee.org
49
50
Email: ledduy@ieee.org
Email: ledduy@ieee.org
4. MT S CU HI THNG GP
4.1. Khng truy cp c trang web
Sau khi ci t xong IIS/PWS nhng th a ch http://localhost/
vn khng chy c. Trong trng hp ny hy kim tra
webserver c khi ng (Start) hay cha hoc kim tra trong
Internet Explorer mc Tools/Internet Options/Connections/LAN
settings xem li cc thit lp ca Proxy server.
JSP: http://www.mycgiserver.com/
PHP: http://www.0php.com/free_PHP_hosting.php,
http://www.free-php-hosting.com/,
4.5. Lm th no ti mt website ln my ch
You might not have permission to view this directory or page using the
credentials you supplied.
51
52
Email: ledduy@ieee.org
Email: ledduy@ieee.org
CU HI
1. Hy cho bit vai tr ca cc phn mm nh IIS v PWS.
53
54
Email: ledduy@ieee.org
Email: ledduy@ieee.org
THC HNH
1. CI T V CU HNH WEBSERVER
Ci t IIS hay PWS ln my ca bn. Sau thc hin tun t
cc bc cu hnh sau:
Thay i th mc Home Directory: To trn my mt th
mc cha website, v d: C:\MyWebSite v cu hnh sao
cho th mc HomeDirectory ca Website tr v th mc ny
thay cho th mc mc nh l C:\InetPub\wwwroot
Vo a ch http://www.freeservers.com
min
ph
vi
a
ch
truy
http://yourname.freeservers.com
ng k website
cp
c
dng
Truy cp theo ng dn n th mc vt l: To th mc
BookStore trong th mc C:\MyWebSite. Sau unzip tp tin
BookStore.zip nm trong AppSamples\BookStore ca a CD
vo th mc ny. Truy cp ng dng BookStore t a ch:
http://localhost/BookStore/
To th mc o: To mt th mc RealEstate ngoi th
mc C:\MyWebSite, v d nh D:\RealEstate. Tip theo unzip
tp
tin
RealEstate.zip
nm
trong
th
mc
AppSamples\RealEstate ca a CD vo th mc ny. Sau
to mt th mc o, ly tn l RealEstate sao cho tr n th
mc D:\RealEstate. Truy cp ng dng RealEstate t a ch:
http://localhost/RealEstate/
Kim tra web server c h tr ASP hay khng: To th
mc D:\MyApp, sau to mt th mc o c tn l MyApp
tr n th mc ny. To mt tp tin default.asp vi ni dung
<% Response.Write Date() %> trong D:\MyApp ri chy th
bng cch g vo a ch: http://localhost/MyApp/default.asp
Cu hnh tp tin mc nh: Kim tra xem cc tp tin mc
nh ca website l g. Sau cu hnh cho website truy
cp cc tp tinh mc nh theo th t sau: default.asp,
index.asp, default.htm, index.htm.
Nu l IIS ci t trn webserver, cu hnh FTP server sao cho
cc user khi kt ni vi server s c chuyn n th mc
C:\MyWebSite.
Cu hnh IIS sao cho c th hosting ng thi nhiu website.
55
56
Email: ledduy@ieee.org
Email: ledduy@ieee.org
G vo a ch m bn d nh ng k ti yourname. Sau
click Go. Mn hnh tip theo s hin ra, bn chn mc cui cng
100% Free Hosting Option v click vo SignUp
57
58
Email: ledduy@ieee.org
Email: ledduy@ieee.org
59
60
Email: ledduy@ieee.org
Email: ledduy@ieee.org
Chng 3
The browser will ignore new lines and extra spaces in the text
This is webpage
<b>This is webpage</b>
This is webpage
This is webpage
on 2
The browser
will ignore new lines
and extra spaces in
the text
on 3
The browser
will
ignore
new lines
and
extra
spaces in the text
61
62
This is webpage
Email: ledduy@ieee.org
Email: ledduy@ieee.org
2. MT S TAG C BN CA HTML
2.2. nh dng vn bn
<HEAD>
<META HTTP-EQUIV="Content-Language" CONTENT="en-us">
<META HTTP-EQUIV="Content-Type" CONTENT="text/html;
charset=utf-8">
<TITLE>Cho mng cc bn n vi trang web ny</TITLE>
</HEAD>
Trong mt phn on, vic ngt dng trong lc son tho khng
nh hng g n vic hin th. Trnh duyt ch hiu ngt dng trong
mt phn on thng qua tag <BR>. V d:
<P>
H tn: L nh Duy
Ngh nghip: Ging vin
a ch: Khoa CNTT H Khoa Hc T Nhin </P>
63
64
Email: ledduy@ieee.org
Email: ledduy@ieee.org
2.2.2. nh dng ch
Tag <FONT> nh dng font ch, mu sc, kch thc, ...
ca vn bn. Cc thuc tnh ca tag ny thng l: FACE: loi font
ch, SIZE: kch thc, COLOR: mu ch. Ngoi ra, nh dng
ch in m ta dng tag <B>, in nghing dng tag <I>, gch di
dng tag <U>.
Thuc tnh COLOR dng trong cc tag thng c nh ngha
bng tn qui c (v d nh RED: mu , BLUE: mu xanh da tri,
...) hoc m RGB di dng 3 ch s h 16 bt u bng du # (v
d nh #FF0000).
V d sau nh dng on vn bn vi font Tahoma, in m, kch
thc +2 (10pt)
<B><FONT FACE="Tahoma" SIZE="2">Thut x th ca ngi
xa</FONT></B>
Cc thuc tnh chnh bao gm: SRC (tn tp tin hnh nh),
WIDTH, HEIGHT (kch thc nh), BORDER (ng vin khung
quanh nh), ALT (vn bn thay th dng khi khng hin th), ALIGN
L nh Duy - H KHTN Tp. HCM
65
66
Email: ledduy@ieee.org
Email: ledduy@ieee.org
(canh chnh), ... Thuc tnh ALT cng c dng khi ta mun a
chut n hnh nh v c dng ch nh tooltip hin th bn di.
Go to chapter 1
Gi email
M tp tin trong ca s nh
ngha bi TARGET
ngha
Np trang web trong ca s hoc FRAME c
tn l name
Np trang web vo mt ca s trng mi.
Ca s mi ny khng c tn.
Np trang web vo ca s cha gn nht
ca trang web hin hnh.
Np trang web vo cng ca s vi trang
web hin hnh. y l gi tr mc nh ca
hyperlink.
Np trang web vo ca s cao nht
(topmost).
Chapter 1
ngha
Hin th ca s ti tp tin theo
giao thc FTP.
<A
HREF=http://www.intel.com>
Intel Home Page</A>
<A HREF="home.htm">
Home</A>
<A
HREF="javascript:window.open()"
> Click here</A>
<A HREF="FlashGet.zip">
Download</A>
M HTML
<A
HREF="ftp://ftp.microsoft.com/mo
use.zip"> Download</A>
<A
HREF="mailto:duyld@yahoo.com"
> Email me</A>
<A HREF="Forum.htm"
TARGET=_blank> Forum</A>
ngha
Lin kt n trang my ch
khc
Lin kt n trang khc trong
cng th mc
Gi mt hm JavaScript
K t cn hin th
<
>
&
khong trng
, #,
1/2 , 1/3, 3 /4
,
,
M thay th
<
>
&
"
¢, £, ¥
¼, ½, ¾
÷, °
®, ©
Hin th ca s ti tp tin v.
67
68
Email: ledduy@ieee.org
Email: ledduy@ieee.org
69
70
Email: ledduy@ieee.org
Email: ledduy@ieee.org
71
72
Email: ledduy@ieee.org
Email: ledduy@ieee.org
K t nhp vo
K t thay th c chuyn i
+
%3D
%0A
%0D
%25
%38
to cc nhp liu dng hp vn bn, nt nhn, checkbox,
radio button, ta dng tag <INPUT> v t gi tr tng ng vi
cc loi nhp liu cho thuc tnh TYPE.
khong trng
=
du xung dng (line feed)
v u dng (carriage return)
%
&
4.1. Hp vn bn (TextBox)
Dng nhp d liu trn mt dng. to nhp liu dng
ny, ta ch nh thuc tnh TYPE=TEXT trong tag <INPUT>. V d
sau minh ha m HTML dng to ra mt nhp liu dng hp
vn bn, c tn l USRNAME, kch thc l 25 k t, gi tr mc nh
l ledduy:
Username: <INPUT TYPE="TEXT" NAME="USRNAME"
VALUE="ledduy" SIZE="20" MAXLENGTH="128">
4.4. Checkbox
73
74
Email: ledduy@ieee.org
Email: ledduy@ieee.org
75
76
Email: ledduy@ieee.org
Email: ledduy@ieee.org
<OPTION VALUE="4">Worker</OPTION>
</SELECT> <BR>
Other information: <TEXTAREA ROWS="3" NAME="OtherInfo"
COLS="20"></TEXTAREA><P><INPUT TYPE="SUBMIT"
NAME="BTNSUBMIT" VALUE="Submit">
<INPUT TYPE="RESET" NAME="BTNRESET" VALUE=" Reset
"></P>
</FORM>
5. FRAME
Ni dung hin th trn trnh duyt c th c tch hp t nhiu
ca s khc nhau, mi ca s cha mt URL tng ng vi mt
trang web. V d sau cho ta thy c ba ca s, mt ca s cha
thc n nm ngang, mt ca s cha thc n bn tri v mt
ca s cha ni dung bn phi. Trong trng hp ny chng ta
dng tag <FRAMESET> v <FRAME> nh ngha.
77
78
Email: ledduy@ieee.org
Email: ledduy@ieee.org
<HTML>
<HEAD>
<TITLE>Welcome to IS-EDU Site</TITLE>
</HEAD>
<FRAMSET BORDER="0" ROWS="80,*" FRAMEBORDER="0">
<FRAME NAME="Banner" SCROLLING="NO" NORESIZE
TARGET="Contents" SRC="GlobalMenu.asp" MARGINWIDTH="0"
MARGINHEIGHT="0">
<FRAMESET COLS="175,*">
<FRAME NAME="Contents" TARGET="Main" SRC="MainMenu.asp"
SCROLLING="AUTO">
<FRAME NAME="Main" SCROLLING="AUTO"
SRC="WebNews/LastNewsAll.asp">
</FRAMESET>
</FRAMESET>
</HTML>
79
80
Email: ledduy@ieee.org
Email: ledduy@ieee.org
<BODY>
<HTML>
<STYLE TYPE="text/css">
<!-BODY {font: 10pt "Arial"}
H1 {font: 15pt/17pt "Arial";
font-weight: bold;
color: maroon}
<P>
<SELECT NAME="NEWS" CLASS="txtInputText">
<OPTION VALUE="TT">Tui Tr</OPTION>
<OPTION VALUE="LD">Lao ng</OPTION>
<OPTION VALUE="TN">Thanh Nin</OPTION>
</SELECT>
</P>
</BODY>
</HTML>
81
82
Email: ledduy@ieee.org
Email: ledduy@ieee.org
THC HNH
1. S DNG PHN MM SWISH TO CC HIU
NG HA N GIN
Phn mm Swish cho php to cc hiu ng ng t n gin
n phc tp. Kt qu cui cng ca ng dng ny l tp tin .swf c
th chy c trn cc trnh duyt c ci t sn Macromedia Flash
Player.
i tng chnh khi son tho mt hiu ng ng trn Swish
c gi l Movie (on phim). Mt movie l tp hp ca nhiu
Scene (phn cnh) khc nhau, mi scence bao gm tp hp cc
Objects (i tng). Hai i tng chnh c h tr trong phin
bn Swish 1.51 l Text Objects (tp cc k t) v Image Objects
(hnh nh). Cc i tng ca scence c th hot hnh (animate)
thng qua vic thit lp cc Effects (hiu ng). Cc hiu ng
c lp trnh sn c th sinh ra cc Frames (khung hnh) tng
ng.
1.1. Ci t Swish
Ci t Swish t a CD. Khi ng ng dng Swish. Mn hnh
lm vic chnh xut hin cng vi View Window
83
84
Email: ledduy@ieee.org
Email: ledduy@ieee.org
85
86
Email: ledduy@ieee.org
Email: ledduy@ieee.org
87
88
Email: ledduy@ieee.org
Email: ledduy@ieee.org
89
90
Email: ledduy@ieee.org
Email: ledduy@ieee.org
91
92
Email: ledduy@ieee.org
Email: ledduy@ieee.org
93
94
Email: ledduy@ieee.org
Email: ledduy@ieee.org
95
96
Email: ledduy@ieee.org
Email: ledduy@ieee.org
GIF
Sau khi thc hin xong vic t hiu ng cho cc frame, nhn
nt F9 hoc chn trn thc n chc nng Animation/Play
Animation xem kt qu.
97
98
Email: ledduy@ieee.org
Email: ledduy@ieee.org
Hnh 3. 37 To mi mt website
Hnh 3. 36 Mn hnh lm vic ca MS FrontPage
99
100
Email: ledduy@ieee.org
Email: ledduy@ieee.org
101
102
Email: ledduy@ieee.org
Email: ledduy@ieee.org
Thc hnh:
G vo mt on vn bn, sau thc hin nh dng theo cc
bc sau:
Dng chut nh du chn mt nhm cc t, sau thc
hin nh dng font ch, kch thc ch, mu ch, hiu ng
ch (nh in m, in nghing, gch di).
Dng chut nh du chn ton b phn on, sau thc
hin nh dng font, border and shading, canh chnh
(alignment).
Chuyn sang tab HTML xem cc tag v cc thuc tnh
tng ng c FrontPage pht sinh.
G vo cc on vn bn, sau s dng nt Bullets hoc
nt Numbering t cc on vn bn ny v nh dng
Bullets hoc Numbering. Thay i thuc tnh ca Bullets v
Numbering va to ra
103
104
Email: ledduy@ieee.org
Email: ledduy@ieee.org
Hnh 3. 42 To mi mt style
L nh Duy - H KHTN Tp. HCM
105
106
Email: ledduy@ieee.org
Email: ledduy@ieee.org
107
108
Email: ledduy@ieee.org
Email: ledduy@ieee.org
109
110
Email: ledduy@ieee.org
Email: ledduy@ieee.org
111
112
Email: ledduy@ieee.org
Email: ledduy@ieee.org
(Page
transition):
Chn
Format/Page
113
114
Email: ledduy@ieee.org
Email: ledduy@ieee.org
Thc hnh:
Thc hin tun t cc bc trn to mt form nh hnh sau:
Hnh 3. 51 Mt mu form
L nh Duy - H KHTN Tp. HCM
115
116
Email: ledduy@ieee.org
Email: ledduy@ieee.org
6.5. VN Express(http://vnexpress.net)
117
118
Email: ledduy@ieee.org
Email: ledduy@ieee.org
thuc tnh style cho nhp liu, v d sau thit lp font ch cho mt
dropdown list box:
7. Nhng cu hi thng gp
7.1. S dng ting Vit Unicode trong cc trang web
c th to ra cc trang web ting Vit s dng bng m
Unicode, trc tin phi t thuc tnh ca trang s dng bng m
Unicode.
Trong
FrontPage,
chn
File/Page
Properties/Language/HTML Encoding/Save the document as/UTF-8
hoc xem meta tag trong phn u ca trang web c thuc tnh
charset l UTF-8 hay cha. V d: <META HTTP-EQUIV="ContentType" CONTENT="text/html; charset=utf-8">.
g c ting Vit, hy s dng mt trong cc phn mm h
tr nh UniKey, VietKey v chn bng m s dng l Unicode.
Khi dng bng m Unicode, chng ta ch c th dng cc font h
tr Unicode nh Arial, Tahoma, Times New Roman, Verdana,
119
120
Email: ledduy@ieee.org
Email: ledduy@ieee.org
Hi: Ti sao khi hin th trang web, font ch khng hin th ging
nh trong lc thit k ca FrontPage
Tr li: C th font hin th lc thit k ca FrontPage l Default
font, do lc hin th trn trnh duyt, trnh duyt s ly font mc
nh c thit lp (v d VNI-Times) tri vi font m FrontPage
dng cho default font (v d Arial). trnh trng hp ny, bn nn
t font cho cc vn bn lc thit k, trnh dng default font.
121
122
Email: ledduy@ieee.org
Email: ledduy@ieee.org
Bi tham kho
123
124
Email: ledduy@ieee.org
Email: ledduy@ieee.org
4. Xy dng ni dung
L mt ngi thit k trang web, bn c th c hoc khng chu
trch nhim to ni dung (nh vn bn, hnh nh, m thanh, video,
..). V vic to ni dung thng khng th i n lc thit k hnh
thnh, bn c th tin hnh cc bc sau m bo rng ni dung
v thit k ca bn l tng thch vi nhau:
Sa i, hiu chnh cc ni dung c hoc cc ni dung m
bn c quyn sa.
Xin h tr v c vn ca nhng chuyn gia i vi cc ch
ngoi lnh vc chuyn mn ca bn.
125
126
Email: ledduy@ieee.org
Email: ledduy@ieee.org
7. Kim tra v nh gi
Cc trang hiu qu nht l kt qu ca vic thit k v nh gi
cn thn. Mt web site tr gi na triu la c th c n 70% tng
chi ph dnh cho vic thit k v nh gi. Sau y l mt s bc
thc hin vic ny:
Kim tra hot ng ca cc lin kt ni b v cc ngun ti
nguyn.
6. a ni dung vo
127
128
Email: ledduy@ieee.org
Email: ledduy@ieee.org
Chng 4
CC NGN NG SCRIPT
H TR LP TRNH WEB
2. S DNG VBSCRIPT
2.1. Cc kiu d liu c bn
VBScript ch c mt kiu d liu duy nht l Variant. Variant l
kiu d liu c bit c th cha cc loi d liu khc nhau t
nhng kiu d liu n gin nh kiu s cho n cc kiu d liu
phc tp nh kiu bn ghi (record). V Variant l kiu d liu duy
nht ca VBScript nn y l cng l kiu d liu c tr v t cc
hm/th tc vit bng VBScript.
Ni mt cch d hiu hn l: nu trong Pascal bn phi lu tr
d liu s trong kiu d liu interger, d liu chui trong kiu d
liu string, th trong VBScript bn c th va lu tr d liu s, va
lu tr d liu chui (hay bt k d liu kiu no khc) trong kiu d
liu Variant. Vic xem mt bin Variant l s hay chui ty vo ng
cnh s dng. V d: trong biu thc b=a+1234 th a, b c xem
nh l kiu s cn trong biu thc b=a+1234, th a, b c xem
nh l kiu chui.
Variant Subtypes: l cc dng thng tin khc nhau m kiu d
liu Variant c th lu tr.
Subtypes
Empty
Null
Boolean
Byte
Integer
Currency
Long
Single
129
130
M t
D liu cha c khi to.
Null
D liu lun l True hoc False
S nguyn c gi tr t 0 n 255
S nguyn c gi tr t -32768 n 32767
T -922,337,203,685,477.5808 n
922,337,203,685,477.5807.
S nguyn c gi tr t -2,147,483,648 n
2,147,483,647.
S thc, c gi tr t 3.402823E38 n 1.401298EEmail: ledduy@ieee.org
Subtypes
Double
Date (Time)
String
Object
Error
Email: ledduy@ieee.org
M t
45 cho cc gi tr m; t 1.401298E-45 n
3.402823E38 cho cc gi tr dng.
S thc, c gi tr t 1.79769313486232E308 n
4.94065645841247E-324 cho cc gi tr m; t
4.94065645841247E-324 n
1.79769313486232E308 cho cc gi tr dng.
Cha gi tr s biu din ngy trong khong
01.01.100 n 31.12.9999.
Chui k t c di thay i. S k t ti a c th
lu tr l 2 t
Cha i tng
Cha m li
V d:
Sub FixDate()
Dim myDate
myDate = #2/13/95#
If myDate < Now Then myDate = Now
End Sub
Qui tc t tn bin:
Phi bt u bng 1 k t ch ci.
V d:
Khng cha du .
Sub AlertUser(value)
If value = 0 Then
AlertLabel.ForeColor = vbRed
AlertLabel.Font.Bold = True
AlertLabel.Font.Italic = True
End If
End Sub
Khng vt qu 255 k t.
khai bo mng, ta dng cp du ( v ) nh ngha cc
s chiu v kch thc mi chiu ca m. V d sau dng khai
bo mt mng mt chiu c 11 phn t: Dim A(10).
Phn t bt u ca mng mt chiu l phn t c ch s l 0.
truy xut ti phn t th i ca mng mt chiu A, ta dng nh
sau: A(i).
131
132
Email: ledduy@ieee.org
Else
End If
Email: ledduy@ieee.org
...
...
<Lnh i>
...
V d:
Sub AlertUser(value)
If value = 0 Then
AlertLabel.ForeColor = vbRed
AlertLabel.Font.Bold = True
AlertLabel.Font.Italic = True
Else
AlertLabel.Forecolor = vbBlack
AlertLabel.Font.Bold = False
AlertLabel.Font.Italic = False
End If
End Sub
V d:
Select Case
Document.Form1.CardType.Options(SelectedIndex).Text
Case "MasterCard"
DisplayMCLogo
ValidateMCAccount
Case "Visa"
DisplayVisaLogo
ValidateVisaAccount
Case "American Express"
DisplayAMEXCOLogo
ValidateAMEXCOAccount
Case Else
DisplayUnknownImage
PromptAgain
End Select
V d:
Sub ReportValue(value)
If value = 0 Then
MsgBox value
ElseIf value = 1 Then
MsgBox value
ElseIf value = 2 then
Msgbox value
Else
Msgbox "Value out of range!"
End If
2.4. Lnh lp
C bn dng lnh lp l Do...Loop, While...Wend, For...Next,
For Each...Next.
133
134
Email: ledduy@ieee.org
Email: ledduy@ieee.org
Do
Do
...
<Lnh i>
...
Loop While <biu thc iu kin>
...
<Lnh i>
...
Loop Until <biu thc iu kin>
V d:
V d:
Sub ChkFirstWhile()
Dim counter, myNum
counter = 0
myNum = 20
Do While myNum > 10
myNum = myNum - 1
counter = counter + 1
Loop
MsgBox "The loop made " & counter & " repetitions."
End Sub
Sub ChkFirstUntil()
Dim counter, myNum
counter = 0
myNum = 20
Do Until myNum = 10
myNum = myNum - 1
counter = counter + 1
Loop
MsgBox "The loop made " & counter & " repetitions."
End Sub
Sub ChkLastWhile()
Dim counter, myNum
counter = 0
myNum = 9
Do
myNum = myNum - 1
counter = counter + 1
Loop While myNum > 10
MsgBox "The loop made " & counter & " repetitions."
End Sub
Sub ChkLastUntil()
Dim counter, myNum
counter = 0
myNum = 1
Do
myNum = myNum + 1
counter = counter + 1
Loop Until myNum = 10
MsgBox "The loop made " & counter & " repetitions."
End Sub
135
136
Email: ledduy@ieee.org
Email: ledduy@ieee.org
<HTML>
<HEAD><TITLE>Forms and Elements</TITLE></HEAD>
<SCRIPT LANGUAGE="VBScript">
<!-Sub cmdChange_OnClick
Dim d 'Create a variable
Set d = CreateObject("Scripting.Dictionary")
d.Add "0", "Athens" 'Add some keys and items
d.Add "1", "Belgrade"
d.Add "2", "Cairo"
V d:
Sub DoMyProc50Times()
Dim x
For x = 1 To 50
MyProc
Next
End Sub
For Each I in d
Document.frmForm.Elements(I).Value = D.Item(I)
Next
End Sub
-->
</SCRIPT>
<BODY>
<CENTER>
<FORM NAME="frmForm"
V d:
Sub TwosTotal()
Dim j, total
For j = 2 To 10 Step 2
total = total + j
Next
MsgBox "The total is " & total
End Sub
<Input Type
<Input Type
<Input Type
<Input Type
<Input Type
Here"><p>
</FORM>
</CENTER>
</BODY>
</HTML>
Sub NewTotal()
Dim myNum, total
For myNum = 16 To 2 Step -2
total = total + myNum
Next
MsgBox "The total is " & total
End Sub
"Text"><p>
"Text"><p>
"Text"><p>
"Text"><p>
"Button" NAME="cmdChange" VALUE="Click
2.5. Hm v th tc
Khai bo th tc
Sub <tn th tc>(<danh sch cc tham s>)
...
End Sub
=
=
=
=
=
137
138
Email: ledduy@ieee.org
Email: ledduy@ieee.org
V d:
Sub ConvertTemp()
temp = InputBox("Please enter the temperature in deg F.", 1)
MsgBox "The temperature is " & Celsius(temp) & " deg C."
End Sub
Khai bo hm
Qui tc t tn bin:
V d:
Function Celsius(fDegrees)
Celsius = (fDegrees - 32) * 5 / 9
End Function
Minh ha cch gi hm, th tc bn trong chng trnh
Temp = Celsius(fDegrees)
MsgBox "The Celsius temp. is " & Celsius(fDegrees) & " deg."
3. S DNG JAVASCRIPT
139
140
Email: ledduy@ieee.org
Email: ledduy@ieee.org
V d
// The smash() function is defined elsewhere in the code.
// Boolean test of whether newShip is true.
if (newShip)
smash(champagneBottle,bow);
// In this example, the test fails unless both conditions are true.
if (rind.color == "deep yellow " && rind.texture == "large and
small wrinkles")
{
theResponse = ("Is it a Crenshaw melon?");
}
3.4. Lnh lp
C bn dng lnh lp l while, do/while, for, for/in.
Cc c php ca lnh while
V d
var x = 0;
while ((x != 42) && (x != null))
{
x = window.prompt("What is my favourite number?", x);
}
if (x == null)
window.alert("You gave up!");
else
window.alert("Yep - it's the Ultimate Answer!");
V d
function MyObject() {
...
}
V d
var x = 0;
do
{
x = window.prompt("What is my favourite number?", x);
} while ((x != 42) && (x != null));
switch (object.constructor){
case Date:
...
case Number:
L nh Duy - H KHTN Tp. HCM
...
case String:
...
case MyObject:
...
default:
...
141
142
Email: ledduy@ieee.org
Email: ledduy@ieee.org
if (x == null)
window.alert("You gave up!");
else
window.alert("Yep - it's the Ultimate Answer!");
V d
var howFar = 10; // Sets a limit of 10 on the loop.
// Creates an array called sum with 10 members, 0 through 9.
var sum = new Array(howFar);
var theSum = 0;
sum[0] = 0;
// Counts from 0 through 9 in this case.
for(var icount = 0; icount < howFar; icount++) { theSum +=
icount;
sum[icount] = theSum;
}
// This isn't executed at all, since icount is not greater than
howFar
var newSum = 0;
for(var icount = 0; icount > howFar; icount++) { newSum +=
icount;
}
var sum = 0;
// This is an infinite loop.
for(var icount = 0; icount >= 0; icount++) { sum += icount;
}
3.5. Hm
Khai bo hm
function <tn hm>(<danh sch cc tham s>){
...
}
4.1. Cch
chn
cc
on
chng
VBScript/JavaScript vo trang HTML
trnh
<HTML>
<HEAD>
<TITLE>Place Your Order</TITLE>
<SCRIPT LANGUAGE="VBScript">
<!--
V d
function add(x, y)
{
return(x + y);
}
143
144
Email: ledduy@ieee.org
Email: ledduy@ieee.org
Function CanDeliver(Dt)
CanDeliver = (CDate(Dt) - Now()) > 2
End Function
-->
</SCRIPT>
</HEAD>
...
<HTML>
<HEAD>
</HEAD>
<BODY>
<SCRIPT LANGUAGE="JavaScript">
<!-x = window.confirm("Are you sure you want to quit?");
if (x)
window.alert("Thank you.")
else
window.alert("Good choice.")
//-->
</SCRIPT>
</BODY>
</HTML>
<HTML>
<HEAD>
</HEAD>
<BODY>
<SCRIPT LANGUAGE="JavaScript">
<!-document.writeln("Welcome to my site!");
//-->
</SCRIPT>
<br>
<SCRIPT LANGUAGE="VBScript">
<!-document.write "This site is under construction"
//-->
</SCRIPT>
</BODY>
</HTML>
145
<HTML>
<HEAD>
<SCRIPT LANGUAGE="VBScript">
<!-Sub vbsEventHandler
146
Email: ledduy@ieee.org
End Sub
Email: ledduy@ieee.org
-->
</SCRIPT>
<SCRIPT LANGUAGE="JavaScript">
<!-function jsEventHandler() {
window.alert ("JavaScript Event Handler");
}
-->
</SCRIPT>
</HEAD>
<BODY>
<INPUT TYPE=BUTTON NAME="vbsBtn" VALUE="VBS Test"
LANGUAGE="VBScript" onclick="vbsEventHandler()">
<INPUT TYPE=BUTTON NAME="jsBtn" VALUE=" JS Test "
LANGUAGE="JavaScript" onclick="jsEventHandler();"><br>
</BODY>
</HTML>
5. Du m VBScript/JavaScript
V mt l thuyt th cc javascript l cc client-side script ngha l
n s c thi hnh ti my ca ngi dng ch khng phi l ti
server. iu c ngha l n phi c ti v my ca ngi dng
lc trang web c gi. Do , ta khng th du c.
6. MT S V D MINH HA
147
<HTML>
<HEAD>
<TITLE>Change BG Color</TITLE>
</HEAD>
<BODY>
<FORM>
<SELECT onChange=
"document.bgColor=this.options[this.selectedIndex].value">
<OPTION VALUE="40E0D0"> Torquoise
<OPTION VALUE="2E8B57"> Sea Green
<OPTION VALUE="87CEEB"> Sky Blue
<OPTION VALUE="F4A460"> Sandy Brown
<OPTION VALUE="FFF0F5"> Lavender Blush
<OPTION VALUE="FF1493"> Deep Pink
<OPTION VALUE="FFFFFF" SELECTED> White
</SELECT>
</FORM>
</BODY>
</HTML>
148
Email: ledduy@ieee.org
Email: ledduy@ieee.org
V d sau minh ha vic cho dng ch chy trn thanh trng thi
ca ca s. Lnh dng thay i ni dung ca thanh trng thi l
window.status=str
<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!-- Start of scroller script
var scrollCounter = 0;
var scrollText = "Welcome to my lesson!";
var scrollDelay = 70;
var i = 0;
<SCRIPT LANGUAGE="JavaScript">
<!-- Hide from non JavaScript browsers
function clockTick()
{
currentTime = new Date();
document.clock_form.clock.value = " "+currentTime;
document.clock_form.clock.blur();
setTimeout("clockTick()", 1000);
}
clockTick();
// End of clock -->
</SCRIPT>
</TD></TR>
</TABLE>
</BODY>
</HTML>
Scroller();
// End of scroller script -->
</SCRIPT>
<TITLE>StatusScroller</TITLE>
</HEAD>
<BODY>
<P>See at your status bar!!!</P>
</BODY>
</HTML>
6.3. ng h
V d sau minh ha vic hin th thi gian h thng hin hnh.
i tng cung cp thng tin v ngy gi l Date
<HTML>
<HEAD>
<TITLE>Clock</TITLE>
</HEAD>
<BODY>
<TABLE BORDER=0 BGCOLOR=BLUE>
L nh Duy - H KHTN Tp. HCM
149
<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!-- Hide code from non-js browsers
function validateForm()
{
formObj = document.sample;
if (formObj.yourname.value == "")
{
alert("You have not filled in the name field.");
formObj.yourname.focus();
return false;
}
else if (formObj.yourage.value == "")
{
150
Email: ledduy@ieee.org
Email: ledduy@ieee.org
}
else if (formObj.yourdob.value == "")
{
alert("You have not filled in your date of birth.");
formObj.yourdob.focus();
return false;
}
var testresults
function checkemail(){
var str=document.validation.emailcheck.value
var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
if (filter.test(str))
testresults=true
else{
alert("Please input a valid email address!")
testresults=false
}
return (testresults)
}
</script>
}
// end hiding -->
</SCRIPT>
<TITLE>FormValidation</TITLE>
</HEAD>
<BODY>
<FORM NAME="sample" METHOD=POST
ACTION="adduser.asp" onSubmit="return validateForm()">
Enter your name :
<INPUT TYPE=TEXT NAME="yourname" SIZE=30><BR>
Enter your age :
<INPUT TYPE=TEXT NAME="yourage" SIZE=3><BR>
Date of birth :
<INPUT TYPE=TEXT NAME="yourdob" SIZE=10><BR>
<INPUT TYPE=SUBMIT> <INPUT TYPE=RESET>
</FORM>
</BODY>
</HTML>
<script>
function checkbae(){
if (document.layers||document.getElementById||document.all)
return checkemail()
else
return true
}
</script>
</BODY>
</HTML>
6.6. Menu
V d sau minh ha mt menu dropdown.
<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript1.2">
/*
Drop down menu link Dynamic Drive (www.dynamicdrive.com)
*/
//Contents for menu 1
var menu1=new Array()
151
152
Email: ledduy@ieee.org
Email: ledduy@ieee.org
}
else{
hidemenu()
function dropit(e,whichone){
if (window.themenu&&themenu.id!=eval(whichone).id)
themenu.visibility="hide"
themenu=eval(whichone)
if (themenu.visibility=="hide")
themenu.visibility="show"
else
themenu.visibility="hide"
themenu.zIndex++
themenu.left=e.pageX-e.layerX
themenu.top=e.pageY-e.layerY+19
return false
}
<STYLE>
<!-.iewrap1{
position:relative;
height:30px;
}
.iewrap2{
position:absolute;
}
#dropmenu0, #dropmenu1{
visibility:hide;
z-index:100;
}
-->
</STYLE>
</HEAD>
function hidemenu(whichone){
if (window.themenu)
themenu.style.visibility="hidden"
}
function hidemenu2(){
themenu.visibility="hide"
}
<BODY>
<SCRIPT LANGUAGE="JavaScript1.2">
//reusable/////////////////////////////
var zindex=100
function dropit2(whichone){
if (window.themenu&&themenu.id!=whichone.id)
themenu.style.visibility="hidden"
themenu=whichone
if (document.all){
if (document.all)
document.body.onclick=hidemenu
//reusable/////////////////////////////
</SCRIPT>
themenu.style.left=document.body.scrollLeft+event.clientXevent.offsetX
themenu.style.top=document.body.scrollTop+event.clientYevent.offsetY+18
if (themenu.style.visibility=="hidden"){
L nh Duy - H KHTN Tp. HCM
themenu.style.visibility="visible"
themenu.style.zIndex=zindex++
153
Email: ledduy@ieee.org
Email: ledduy@ieee.org
false">
<font face=Verdana><b><a href="alternate.htm"
onClick="if(document.layers) return dropit(event,
'document.dropmenu0')">Local Links</a></b></font>
</span>
</span>
</layer>
</ilayer><br>
<!----------Menu 1 ends here---------->
}
</SCRIPT>
<DIV id=dropmenu1 STYLE="position:absolute;left:0;top:0;layerbackground-color:lightyellow;backgroundcolor:lightyellow;width:120;visibility:hidden;border:2px solid
black;padding:0px">
<SCRIPT LANGUAGE="JavaScript1.2">
if (document.all)
dropmenu1.style.padding="4px"
for (i=0;i<menu2.length;i++)
document.write(menu2[i])
</SCRIPT>
</DIV>
<SCRIPT LANGUAGE="JavaScript1.2">
if (document.layers){
document.dropmenu1.captureEvents(Event.CLICK)
document.dropmenu1.onclick=hidemenu2
}
</SCRIPT>
</BODY>
</HTML>
155
156
Email: ledduy@ieee.org
Email: ledduy@ieee.org
THC HNH
http://javascript.internet.com/
www.dynamicdrive.com
http://javascript.com/
http://www.mjtnet.com/resources.htm
Tham kho cc website trn ng dng vo:
=To mt lch (calender), cho php ngi dng chn ngy,
thng, nm cho cc ng dng lin quan n xp lch hay chn
ngy
thng
nm
sinh.
Tham
kho:
http://javascript.internet.com/calendars/dynamic.html
157
158
Email: ledduy@ieee.org
Email: ledduy@ieee.org
Chng 5
NHP MN ASP
D liu vn bn (text)
Cc tag HTML
</HTML>
L nh Duy - H KHTN Tp. HCM
159
160
Email: ledduy@ieee.org
Email: ledduy@ieee.org
dtmHour = Hour(Now())
If dtmHour < 12 Then
%>
Good Morning!
<%
Else
%>
Hello!
<%
End If
%>
</BODY>
</HTML>
i vi VBScript, ta dng k t . V d:
<%
'This line and the following two are comments.
'The PrintTable function prints all
'the elements in an array.
PrintTable MyArray()
%>
161
162
Email: ledduy@ieee.org
Email: ledduy@ieee.org
163
hello.asp
<HTML>
<HEAD>
<TITLE>Output data</TITLE>
</HEAD>
<BODY>
<%
FName = Request.QueryString("FirstName")
LName = Request.QueryString("LastName")
Gender = Request.QueryString("Gender")
%> <p>Hello
<%
Response. Write Gender & " " & FName & " " & LName
%>
</BODY>
</HTML>
164
Email: ledduy@ieee.org
Email: ledduy@ieee.org
4. X L CC KT XUT D LIU
Trong m chng trnh pha client (t trong cp tag <SCRIPT>
v </SCRIPT>), gi d liu ra trang web hin hnh, bn dng
phng thc document.write. Tng t nh vy, gi d liu ra
trang web ngay trong on m ASP (t trong cp tag <% v %>),
bn dng phng thc Response.Write
Sau y l mt s v d khi s dng phng thc ny:
In mt hng kiu s, v d nh 5: Response.Write 5
In mt hng chui, v d nh Hello World:
Response.Write Hello World. Lu rng, hng chui bao
gi cng c ro quanh bi cp du nhy n () hoc nhy
kp ().
In mt gi tr ca mt bin, v d nh bin FirstName:
Response.Write FirstName
In kt hp cc dng d liu trn, ta dng ton t &. V d:
Response.Write No & 1 & FirstName
Khi mun xut ra mt chui di, ta c th chia nh chui ny
thnh nhiu dng bng cch s dng chui k t: &_. V d:
<%
Response.Write "Cho mng cc bn n vi website" &_
"ca Trng H Khoa Hc T Nhin"
%>
<%
Response.Write "He said, "This doesnt work!""
%>
165
166
Email: ledduy@ieee.org
Email: ledduy@ieee.org
Stand"><br>
<HTML>
<HEAD>
</HEAD>
<BODY>
Response.Write "<B>Hyperion</b> by <I>Dan Simmons</i> is
a great novel"
Response.Write "<p>"
Response.Write server.htmlencode("<B>Hyperion</b> by
<I>Dan Simmons</i> is a great novel")
Response.Write "<p>"
Response.Write "Joe Smith & Hilda = a team"
Response.Write "<p>"
Response.Write server.URLencode("Joe Smith & Hilda = a team")
%>
</BODY>
</HTML>
<%
Response.Write "Which Book? <input type=""TEXT""
name=""book"" value=""The Stand""><br>"
%>
<%
Response.Write "Which Book? <input type='TEXT' name='book'
value='The Stand'><br>"
%>
<%
quote=chr(34)
Response.Write "Which Book? <input type=" & quote & "TEXT" &
quote & " name=" & quote & "book" & quote & " value=" & quote &
"The Stand" & quote & "><br>"
%>
<%bookname="The Stand"%>
Which Book? <input type="TEXT" name="book"
value="<%=bookname%>"><br>
4.3. Mt s v d minh ha
Sau y l mt s v d minh ha vic nhng cc on m ASP
cng vi m HTML cho cc kt xut thng gp trong lp trnh.
4.3.1. V d 1: Trn ln cc dng kt xut trong trang ASP
V d sau minh ho vic trn ln cc dng kt xut bng cch
dng phng thc Response.Write, <%=%> hay trn ln m HTML
gia cc lnh iu khin ASP, ng thi minh ha vic s dng
uyn chuyn cc phng php dng du nhy.
<%
Response.Write "Which Book? <input type=""TEXT""
name=""book"" value=""" & bookname & """><br>"
%>
</FORM>
</BODY>
</HTML>
<HTML>
<HEAD>
</HEAD>
<BODY>
<%
Response.Write "<FORM>"
Response.Write "Hello, Joe<br>"
UsrName="Joe"
Response.Write "Hello, " & UsrName & "<br>"
%>
Hello, <%=UsrName%><br>
Which Book? <input type="TEXT" name="book" value="The
L nh Duy - H KHTN Tp. HCM
167
168
Email: ledduy@ieee.org
Email: ledduy@ieee.org
<FORM>
Year <SELECT NAME= "Year" >
<%
for i=1930 to 1980
Response.Write "<OPTION VALUE=" & i & ">"
Response.Write i & "</OPTION>"
next
%>
</SELECT>
</FORM>
Hnh 1 Kt qu ca on m trn
TT MSSV
H v Tn
Ghi ch
1
99001
A1
2
99002
A2
..
99 990099
A99
M HTML ca bng d liu ny c dng:
<FORM>
Year <SELECT NAME= "Year" >
<OPTION VALUE="1930">1930</OPTION>
<OPTION VALUE="1931">1931</OPTION>
<OPTION VALUE="1932">1932</OPTION>
<OPTION VALUE="1980">1980</OPTION>
</SELECT>
</FORM>
169
170
Email: ledduy@ieee.org
Email: ledduy@ieee.org
<TD>A1</TD>
<TD> </TD>
</TR>
<TR>
<TD>2</TD>
<TD>99002</TD>
<TD>A2</TD>
<TD> </TD>
</TR>
<TR>
<TD>99</TD>
<TD>990099</TD>
<TD>A99</TD>
<TD> </TD>
</TR>
</TABLE>
5. KT NI VI C S D LIU
ADO (ActiveX Data Object) c dng cung cp kh nng
kt ni v x l trn c s d liu. Ta c th s dng ADO kt ni
vi ngun d liu tng thch vi OLE DB nh c s d liu, bng
tnh, tp tin tun t, OLE DB l giao din lp trnh mc h thng
cung cp tp cc giao tip COM chun khai thc cc chc nng
qun tr h c s d liu. Ngoi ra ta cng c th s dng ADO
truy xut n cc c s d liu tng thch vi ODBC.
Vic s dng ADO truy cp v x l c s d liu trong cc
trang ASP c th chia lm cc bc chnh sau:
Kt ni vi d liu thng qua OLE DB hoc ODBC
Xy dng cu truy vn d liu v yu cu thc hin cu truy
vn thc hin cc thao tc x l trn c s d liu nh
thm, xa, sa, lc d liu,
5.1. Kt ni vi c s d liu
5.1.1. To connection string
Ging nh khi bn mun tr chuyn bng in thoi, bc u
tin l phi quay s in thoi ca ngi m bn cn tr chuyn.
c th x l d liu, bc u tin, bn phi cung cp cc thng tin
cn thit h thng bit bn mun truy cp ti c s d liu no.
Mt chui k t gi l connection string s c dng lu tr cc
thng tin ny, bao gm:
Thng tin v h qun tr c s d liu c dng qun l
c s d liu ca bn. V d l MS Access hoc MS SQL
hay Oracle,
Thng tin v v tr ca c s d liu ca bn. V d: nu bn
dng MS Access, bn phi ch ra c s d liu ca bn c
lu trong tp tin .mdb no.
Bng sau lit k cc OLE DB connection string cho mt s h
qun tr c s d liu thng dng:
171
172
Email: ledduy@ieee.org
Data Source
Email: ledduy@ieee.org
Microsoft
Access
Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=physical path to .mdb file
Microsoft SQL
Server
Provider=SQLOLEDB.1;Data Source=path to
database on server
Oracle
Provider=MSDAORA.1;Data Source=path to
database on server
Microsoft
Indexing
Service
Microsoft SQL
Server
DRIVER={SQL Server};SERVER=path to
server
Oracle
Microsoft Excel
Microsoft Excel
97
Paradox
Text
Microsoft
Visual FoxPro
(with a
database
container)
Microsoft
Visual FoxPro
(without a
database
container)
Microsoft
Access
Data Source
Driver
173
174
Email: ledduy@ieee.org
Email: ledduy@ieee.org
<%
strDSN = Driver={Microsoft Access Driver (*.mdb)};DBQ= &
server.mappath(Test.mdb)
5.2.
update.asp
<%
strDSN = Driver={Microsoft Access Driver (*.mdb)};DBQ= &
server.mappath(Test.mdb)
L nh Duy - H KHTN Tp. HCM
175
176
Email: ledduy@ieee.org
Email: ledduy@ieee.org
5.3.1. Lu tr d liu tr v
i=1
do while not rsCustomers.EOF
Response.Write Customer No & i & .
Response.Write rsCustomers(FirstName) & &
rsCustomers(LastName) & <br>
i = i+1
rsCustomers.MoveNext
loop
%>
C ba vn lu :
Kt qu th hin s c dng:
177
Email: ledduy@ieee.org
Email: ledduy@ieee.org
rsCustomers.Close
Set rsCustomers = Nothing
Conn.Close
Set Conn= Nothing
%>
6. NHNG CU HI THNG GP
6.1. Lm th no bt u hc ASP
i=1
do while not rsCustomers.EOF
Response.Write Customer No & i & .
Response.Write rsCustomers(FirstName) & &
rsCustomers(LastName) & <br>
i = i+1
rsCustomers.MoveNext
loop
Free resource
L nh Duy - H KHTN Tp. HCM
179
180
Email: ledduy@ieee.org
Email: ledduy@ieee.org
http://www.learnasp.com
http://www.4guysfromrolla.com
http://www.15seconds.com
http://asp.superexpert.com
http://www.aspfaqs.com
6.5. Lm th no bo v on m ASP
pha ngi dng thng thng s khng bit c ni dung
ca on m ASP v khi truy cp mt trang ASP, webserver
thng dch v x l cc on m trong v ngi dng ch thy
c kt qu tr v di dng trang HTML. Chnh v vy, cch duy
nht c th xem c m ca trang ASP l bn phi c quyn trn
webserver cha trang . Nu bn mun trnh khng mun cho bit
ni dung on m ny lun, th c mt trong hai cch sau:
Vit ng dng ca bn di dng cc component .DLL. y
l cch m cc nh cung cp dch v cng thm hay lm v d
nh component h tr ti tp tin ln server, component h tr
gi email, Hn ch ca cch lm ny l bn phi c quyn
181
182
Email: ledduy@ieee.org
Email: ledduy@ieee.org
THC HNH
1. S GP
Trong cc website, tip thu kin ca khch gh thm, ngi
ta thng to mt s gp trn web, cho php cc chc nng sau:
Cho php ngi dng nhp vo cc thng tin h tn, a ch
email, v ni dung gp .
Cho php ngi dng xem ton b cc ni dung gp .
Th t cc gp c sp xp theo thi gian.
Cho php qun tr hiu chnh, xa cc gp .
183
184
Email: ledduy@ieee.org
Email: ledduy@ieee.org
Bi tham kho
185
1251
1252
1253
1254
1258
etc.,
upper
Eastern
Cyrillic
West
Greek
Turkish
Vietnamese etc.,
128
Europe
ASCII
ASCII
ASCII
Euro
ANSI
lower
ASCII
ASCII
ASCII
etc.,
128
Email: ledduy@ieee.org
Email: ledduy@ieee.org
187
188
Email: ledduy@ieee.org
Email: ledduy@ieee.org
</BODY>
</HTML>
%>
<%
189
190
Email: ledduy@ieee.org
Email: ledduy@ieee.org
<%@CODEPAGE=65001%>
<%Session.Codepage=65001%>
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html;
CHARSET=UTF-8">
</HEAD>
<BODY>
</BODY>
</HTML>
3. H tr Unicode ca cc phn mm
3.1. Cc phn mm h tr son tho trang web
Visual Studio.NET, Notepad, MS FrontPage2002: H tr lu
tp tin di dng UTF-8
Visual InterDev 6.0: Nu trong trang asp ta s dng cc hng
chui c g vo di dng Unicode, v d nh:
L nh Duy - H KHTN Tp. HCM
191
192
Email: ledduy@ieee.org
Email: ledduy@ieee.org
6. Ti liu trch dn
1. http://www.microsoft.com/globaldev/articles/unicode.asp
2. http://www.unicode.org/unicode/standard/principles.html
3. http://support.microsoft.com/default.aspx?scid=kb;enus;Q303612
4. http://msdn.microsoft.com/library/default.asp?url=/workshop/a
uthor/dhtml/reference/charsets/charset4.asp
5. http://www.w3.org/TR/html401/charset.html#code-position
6. http://support.microsoft.com/default.aspx?scid=KB;ENUS;Q295063&
7. http://msdn.microsoft.com/library/default.asp?url=/library/enus/iisref/html/psdk/asp/vbob150l.asp
8. http://support.microsoft.com/default.aspx?scid=kb;enus;Q239530
9. http://support.microsoft.com/default.aspx?scid=kb;enus;q232580
10. http://support.microsoft.com/default.aspx?scid=kb;enus;Q245000
11. http://support.microsoft.com/default.aspx?scid=kb;enus;Q245000
5. Kt lun
12. http://support.microsoft.com/default.aspx?scid=kb;[LN];Q254
313
193
194
Email: ledduy@ieee.org
Email: ledduy@ieee.org
Bi tham kho
Bn lun:
u im ca cch lm trn l cho php bn s dng cc on
m sn c lc kt xut d liu ra dng bng theo cch thng thng
chuyn sang nh dng Excel. Tuy nhin vic kt xut d liu
theo nh dng Excel nh trong v d trn c th chim ti nguyn
ca webserver c bit khi d liu ln do ch nn dng cch ny
nu trang ny khng c s dng thng xuyn.
Nu mun kt xut d liu ln v thc hin thng xuyn, ta c
th kt xut thng qua nh dng CSV (Comma-Separated Values)
ti u hn. Cc tp tin theo nh dng CSV l cc tp tin vn bn
m d liu trong cc ct c ngn cch vi nhau bi du phy ,
(comma), rt thng c dng cho vic trao i d liu gia cc
h qun tr CSDL v cc chng trnh bng tnh nh Excel. V d,
nu bn m mt tp tin csv c ni dung nh sau trong Excel, ta s
nhn c mt bng 3 dng, 3 ct:
kt ni vi CSDL
strDSN = "DRIVER=Microsoft Access Driver (*.mdb);DBQ="
ng dn tng i n tp tin CSDL
strDSN = strDSN & Server.MapPath("myDB.mdb")
set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open strDSN
strSQL = SELECT * FROM myTable
set rs = Conn.Execute(strSQL)
L nh Duy - H KHTN Tp. HCM
%>
rowstart = <tr>
rowend = </tr>
cellstart = <td>
cellend = </td>
Response.Write <TABLE border=1>
dng u tin in tn cc ct
Response.Write rowstart
For i = 0 to rs.Fields.Count -1
Response.Write cellstart & "<b>" & rs.Fields(i).name &
"</b>" & cellend
Next
Response.Write rowend
in d liu ca tng dng
Do while not rs.EOF
Response.Write rowstart
For i = 0 to rs.Fields.Count 1
Response.Write cellstart & rs.Fields(i)& cellend
Next
Response.Write rowend
rs.MoveNext
Loop
rs.Close
set rs = Nothing
Conn.Close
set Conn = nothing
Response.Write </TABLE>
Response.End
195
196
Email: ledduy@ieee.org
Email: ledduy@ieee.org
Doe,John,944-7077
Johnson,Mary,370-3920
%>
Smith,Abigail,299-3958
chuyn d liu sang nh dng CSV, vn vi cch lm tng
t bng cch thay i thuc tnh ContentType v dng
application/csv v thm dng lnh sau yu cu trnh duyt hin
th hp thoi ti tp tin v: Response.AddHeader "ContentDisposition", "filename=mydata.csv;". Sau , thay v nh dng d
liu di dng bng, ta nh dng d liu theo dng d liu cc ct
c phn cch vi nhau bng du phy ,. Xem v d minh ha
sau:
<%
Response.Buffer = True
Response.Clear
thit lp nh dng s kt xut l Excel
Response.ContentType = application/csv
Response.AddHeader
"Content-Disposition",
"filename=mydata.csv;"
kt ni vi CSDL
strDSN = "DRIVER=Microsoft Access Driver (*.mdb);DBQ="
ng dn tng i n tp tin CSDL
strDSN = strDSN & Server.MapPath("myDB.mdb")
set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open strDSN
strSQL = SELECT * FROM myTable
set rs = Conn.Execute(strSQL)
dng u tin in tn cc ct
For i = 0 to rs.Fields.Count -1
Response.Write rs.Fields(i).name & ",
Next
Response.Write vbNewLine kt thc mt dng d liu
in d liu ca tng dng
Do while not rs.EOF
For i = 0 to rs.Fields.Count 1
Response.Write rs.Fields(i)& ,
Next
Response.Write vbNewLine kt thc mt dng d liu
rs.MoveNext
Loop
rs.Close
set rs = Nothing
Conn.Close
197
198
Email: ledduy@ieee.org
Email: ledduy@ieee.org
Chng 6
199
<%
'Check to see if the client is connected.
If Not Response.IsClientConnected Then
'Get the sessionid to send to the shutdown function.
Shutdownid = Session.SessionID
200
Email: ledduy@ieee.org
Email: ledduy@ieee.org
2. I TNG REQUEST
2.1. Request.Form v Request.QueryString
Request.Form c dng cho trng hp ta mun ly gi tr
ca cc bin kt hp vi cc control ca form c gi i bng
method POST. i vi trng hp mt control cha nhiu gi tr,
chng ta phi ch nh th t (index) ca gi tr cn ly. bit s
lng cc gi tr c gi theo mt control, ta tham chiu n thuc
tnh Count. V d:
2.2. Request.ServerVariables
<%
For i = 1 to Request.Form("FavoriteFlavor").count
%>
Request.Form(FavoriteFlavor) =
<%= Request.Form("FavoriteFlavor")(i)%> <BR>
<% Next %>
Variable
Description
ALL_HTTP
ALL_RAW
APPL_MD_PATH
201
202
Email: ledduy@ieee.org
APPL_PHYSICAL_PATH
AUTH_PASSWORD
AUTH_TYPE
Email: ledduy@ieee.org
CERT_SECRETKEYSIZE
CERT_SERIALNUMBER
CERT_SERVER_ISSUER
CERT_SERVER_SUBJECT
CERT_SUBJECT
CONTENT_LENGTH
CONTENT_TYPE
GATEWAY_INTERFACE
HTTP_<HeaderName>
AUTH_USER
CERT_COOKIE
CERT_FLAGS
CERT_ISSUER
CERT_KEYSIZE
203
204
Email: ledduy@ieee.org
Email: ledduy@ieee.org
HTTP_ACCEPT
HTTP_ACCEPT_LANGUAGE
HTTP_USER_AGENT
HTTP_COOKIE
HTTP_REFERER
HTTPS
HTTPS_KEYSIZE
HTTPS_SECRETKEYSIZE
HTTPS_SERVER_ISSUER
HTTPS_SERVER_SUBJECT
205
INSTANCE_ID
INSTANCE_META_PATH
LOCAL_ADDR
LOGON_USER
PATH_INFO
PATH_TRANSLATED
A translated version of
PATH_INFO that takes the path
and performs any necessary
virtual-to-physical mapping.
QUERY_STRING
206
Email: ledduy@ieee.org
Email: ledduy@ieee.org
REMOTE_ADDR
SERVER_SOFTWARE
REMOTE_HOST
URL
REMOTE_USER
REQUEST_METHOD
SCRIPT_NAME
SERVER_NAME
SERVER_PORT
SERVER_PORT_SECURE
SERVER_PROTOCOL
207
3. APPLICATION V SESSION
Nh chng ta bit, nu mt bin c khai bo trong mt
trang ASP, n s b hy ngay mt khi server x l xong trang ny.
c th khai bo cc bin c th s dng chung cho nhiu trang, ta
s dng hai i tng Application v Session.
208
Email: ledduy@ieee.org
Email: ledduy@ieee.org
%>
...
<%
Set MyLocalObj1 = Application("Obj1")
MyLocalObj1.MyObjMethod
%>
<%
Application.Lock
Application("NumVisits") = Application("NumVisits") + 1
Application.Unlock
%>
This application page has been visited
<%= Application("NumVisits") %> times!
---file1.asp--<%
'Creating and initializing the array.
dim MyArray()
Redim MyArray(5)
MyArray(0) = "hello"
MyArray(1) = "some other string"
209
Email: ledduy@ieee.org
Email: ledduy@ieee.org
<%
MyArTemp = Session("MyArray")
MyArTemp(0) = 4
Session("MyArray") = MyArTemp
%>
211
Response.Redirect("file2.asp")
%>
---file2.asp--<%
'Retrieving the array from the Session Object
'and modifying its second element.
LocalArray = Session("StoredArray")
LocalArray(1) = " there"
'Printing out the string "hello there."
Response.Write(LocalArray(0)&LocalArray(1))
'Re-storing the array in the Session object.
'This overwrites the values in StoredArray with the new one.
Session("StoredArray") = LocalArray
%>
212
Email: ledduy@ieee.org
Email: ledduy@ieee.org
3.3. GLOBAL.ASA
Nu ta mun thc hin mt s thao tc ngay khi h thng to ra
cc i tng Application, Session. ta phi t cc thao tc ny
trong th tc Application_OnStart, Session.On_Start tng ng.
Tng t, thc hin cc thao tc trc khi h thng chun b hy b
cc i tng ny, ta phi t cc thao tc ny trong th tc
Application_OnEnd, Session.On_End tng ng.
Path: Xc nh ng dn m cookie c gi i.
Sub Application_OnEnd
...
End Sub
Sub Session_OnStart
...
End Sub
Sub Session_OnEnd
...
End Sub
ly gi tr t cookie, ta dng
Request.Cookies(cookie)[(key)|.attribute].
</SCRIPT>
php
sau:
4. COOKIES
Cookie l thng tin ca ng dng web lu tr ti my client.
Thng thng cc cookie lu tr cc thng tin ring ca bn khi s
dng mt website no . V d, nu bn dng Yahoo Mail, thng tin
v tn ng nhp ca bn c th s c lu vo cookie my bn
ang dng nh tn ng nhp ca bn. l l do ti sao sau
ny khi quay li trang Yahoo Mail, h thng s t ng hin th tn
ng nhp ca bn trc v ch yu cu bn nhp vo mt khu.
Vi giao thc HTTP, mi yu cu cho mt trang web khng c
mi lin quan no vi cc yu cu khc. Chnh v vy m webserver
khng nh c trang no c gi n cho ngi dng trc
hay bt c nhng g m ngi dng duyt qua. Cookie l mt
sau:
213
---cookiesform.asp--<%
Response.Buffer=true
%>
<HTML>
<HEAD>
<TITLE>cookiesform.asp</TITLE>
<BODY bgcolor="#FFFFFF">
<%
ln=Request.Cookies("thatperson")("lastname")
fn=Request.Cookies("thatperson")("firstname")
st=Request.Cookies("thatperson")("state")
%>
<FORM ACTION = "cookiesformrespond.asp">
Form with Cookies<p>
214
Email: ledduy@ieee.org
Email: ledduy@ieee.org
Response.Buffer=true
%>
<HTML>
<HEAD>
<TITLE>cookiesformforget.asp</TITLE>
<BODY bgcolor="#FFFFFF">
<%
cookiepath="/learn/test"
cookiedomain=".www.activeserverpages.com"
cookiesdie=date-365
Response.Cookies("thatperson").Expires = cookiesdie
Response.Cookies("thatperson").Domain = cookiesdomain
Response.Cookies("thatperson").Path = cookiespath
Response.Write "I will not remember you"
%>
</BODY>
</HTML>
---cookiesformrespond.asp--<%
Response.Buffer=true
%>
<HTML>
<HEAD>
<TITLE>cookiesformrespond.asp</TITLE>
<BODY bgcolor="#FFFFFF">
<%
l=request.querystring("namelast")
f=request.querystring("namefirst")
st=request.querystring("state")
cookypath="/learn/test"
cookydomain=".www.activeserverpages.com"
cookydie=date+365
Response.Cookies("thatperson")("lastname") = l
Response.Cookies("thatperson")("firstname") = f
Response.Cookies("thatperson")("state") = st
Response.Cookies("thatperson").Expires = cookydie
Response.Cookies("thatperson").Domain = cookydomain
Response.Cookies("thatperson").Path = cookypath
Response.Write Request.Cookies("thatperson")("lastname") &
"<p>"
Response.Write Request.Cookies("thatperson")("firstname") &
"<p>"
Response.Write Request.Cookies("thatperson")("state") & "<p>"
%>
</BODY>
</HTML>
5. I TNG SERVER
i tng Server cung cp cc thuc tnh v phng thc h
tr cho cc chc nng mc server.
ch nh khong thi gian m mt on m script c th thi
hnh trn server trc khi ht thi gian cho php (time out), ta t
gi tr (tnh bng giy) cho thuc tnh Server.ScriptTimeOut. V d:
<%Server.ScriptTimeOut=100%>
gi thi hnh mt trang asp khc nh th n l mt phn ca
trang asp hin hnh, ta dng phng thc Server.Execute. V d:
<%Server.Execute("Welcome.asp")%>.
chuyn mt chui v dng m HTML, ta dng phng thc
Server.HTMLEncode.
V
d
lnh
sau:
<%= Server.HTMLEncode("The paragraph tag: <P>") %> s sinh
ra chui kt qu l: The paragraph tag: <P>. Trn mn hnh s
hin th: The paragraph tag: <P>.
nh x ng dn o thnh ng dn thc ch ni lu tr
vt l thc s trn my, ta dng phng thc
Server.MapPath(Path)
Trong v d sau, tp tin data.txt c lu tr ti th mc
C:\Inetpub\Wwwroot\Script cng vi tp tin test.asp. Th mc
C:\Inetpub\Wwwroot directory c coi nh nh l webroot (server's
home directory).
215
216
Email: ledduy@ieee.org
Email: ledduy@ieee.org
<%
Response.Write(Server.URLEncode("http://www.microsoft.com"))
%>
Kt qu l c:\inetpub\wwwroot\script\test.asp<BR>
Cc v d sau minh ha vic nh x sang th mc vt l cn c
vo cch t ng dn l tng i hay tuyt i. Mt ng dn
tng i l ng dn khng bt u bng du / hay \.
V d 1:
<%= Server.MapPath("data.txt")%><BR>
<%= Server.MapPath("script/data.txt")%><BR>
V d 2:
<%= Server.MapPath("/script/data.txt")%><BR>
<%= Server.MapPath("\script")%><BR>
6. X L LI VI I TNG ASPERROR
Bn c th s dng cc thuc tnh ca i tng ASPError
by cc li xy ra trong on m script ca trang web v t
a ra cc thng bo v x l tng ng.
<%
Response.Write objASPError.Category
If objASPError.ASPCode > "" Then Response.Write ", " &
objASPError.ASPCode
Response.Write " (0x" & Hex(objASPError.Number) & ")" & "<br>"
Response.Write "<b>" & objASPError.Description & "</b><br>"
If objASPError.ASPDescription > "" Then Response.Write
objASPError.ASPDescription & "<br>"
blnErrorWritten = False
' Only show the Source if it is available and the request is from the
same machine as IIS
If objASPError.Source > "" Then
strServername =
LCase(Request.ServerVariables("SERVER_NAME"))
strServerIP = Request.ServerVariables("LOCAL_ADDR")
strRemoteIP = Request.ServerVariables("REMOTE_ADDR")
If (strServername = "localhost" Or strServerIP = strRemoteIP)
And objASPError.File <> "?" Then
ASP2.asp
<HTML>
<BODY>
<%
Response.Write Session.SessionID
%>
</BODY>
</HTML>
L nh Duy - H KHTN Tp. HCM
s in ra chui: http%3A%2F%2Fwww%2Emicrosoft%2Ecom
Kt qu l: c:\inetpub\wwwroot\script\data.txt<BR>
Kt qu l : c:\inetpub\wwwroot\script\data.txt<BR>
c:\inetpub\wwwroot\script<BR>
217
218
Email: ledduy@ieee.org
Email: ledduy@ieee.org
Response.Write objASPError.File
If objASPError.Line > 0 Then Response.Write ", line " &
objASPError.Line
If objASPError.Column > 0 Then Response.Write ", column " &
objASPError.Column
Response.Write "<br>"
Response.Write "<font style=""COLOR:000000; FONT: 8pt/11pt
courier new""><b>"
Response.Write Server.HTMLEncode(objASPError.Source) &
"<br>"
If objASPError.Column > 0 Then Response.Write
String((objASPError.Column - 1), "-") & "^<br>"
Response.Write "</b></font>"
blnErrorWritten = True
End If
End If
If Not blnErrorWritten And objASPError.File <> "?" Then
Response.Write "<b>" & objASPError.File
If objASPError.Line > 0 Then Response.Write ", line " &
objASPError.Line
If objASPError.Column > 0 Then Response.Write ", column " &
objASPError.Column
Response.Write "</b><br>"
End If
%>
219
220
Email: ledduy@ieee.org
Email: ledduy@ieee.org
c hin th
1)*nPageSize+1
trang
ny
l:
(nPageNum-
trong
221
222
'like
AND " & " AUTHOR LIKE " & "'%" & Author &
AND " & " PUBLISHER LIKE " & "'%" & Publisher
Email: ledduy@ieee.org
Email: ledduy@ieee.org
strSQL = strSQL & " AND " & " YEARPUB LIKE " & "'%" & YearPub &
"%'"
set rs = Server.CreateObject("ADODB.Recordset")
rs.CursorType = 3
rs.CursorLocation = 3 aduseclient
rs.ActiveConnection = Conn
rs.Open strSQL
rs.Pagesize = PageSize
rs.Absolutepage = PageNum
TotalPage = Cint(rs.PageCount)
if rs.eof then
Response.Write "No records is matched!"
Response.End
end if
%>
Total Page: <%=rs.RecordCount%>
<p> Page </p>
<%
sURL = Request.ServerVariables("SCRIPT_NAME")
sURL= sURL & "?fmTITLE=" & Title
sURL= sURL & "&fmAUTHOR=" & Author
sURL= sURL & "&fmPUBLISHER=" & Publisher
sURL= sURL & "&fmYEARPUB=" & YearPub
sURL= sURL & "&PageSize=" & PageSize
for i=1 to TotalPage
if i<10 then
Response.Write "<a href='" & sURL & "&PageNo=" & i & "'>" &
"0" & i & "</a>" & " "
else
Response.Write "<a href='" & sURL & "&PageNo=" & i & "'>" &
i & "</a>" & " "
end if
next
%>
<TABLE border="1" cellpadding="0" cellspacing="0" width="1000"
>
<tr>
<td width="50" align="center"><b>No</b></td>
<td width="100" align="center"><b>ISBN</b></td>
<td width="300" align="center"><b>Title</b></td>
<td width="250" align="center"><b>Abstract</b></td>
<td width="150" align="center"><b>Authors</b></td>
<td width="100" align="center"><b>Publisher</b></td>
<td width="50" align="center"><b>Year</b></td>
L nh Duy - H KHTN Tp. HCM
223
</tr>
<%
i=1
do while (not rs.eof) AND (i<=PageSize)
%>
<tr>
<td width="50"><%=i%> </td>
<td width="100"><%=rs("ISBN")%> </td>
<td width="300"><%=rs("TITLE")%> </td>
<td width="250"><%=rs("ABSTRACT")%> </td>
<td width="150" ><%=rs("AUTHOR")%> </td>
<td width="100" ><%=rs("PUBLISHER")%> </td>
<td width="50"><%=rs("YEARPUB")%> </td>
</tr>
<%
i = i+1
rs.movenext
loop
%>
</TABLE>
Total Page: <%=rs.RecordCount%>
<p> Page </p>
<%
sURL = Request.ServerVariables("SCRIPT_NAME")
sURL= sURL & "?fmTITLE=" & Title
sURL= sURL & "&fmAUTHOR=" & Author
sURL= sURL & "&fmPUBLISHER=" & Publisher
sURL= sURL & "&fmYEARPUB=" & YearPub
sURL= sURL & "&PageSize=" & PageSize
for i=1 to TotalPage
if i<10 then
Response.Write "<a href='" & sURL & "&PageNo=" & i & "'>" &
"0" & i & "</a>" & " "
else
Response.Write "<a href='" & sURL & "&PageNo=" & i & "'>" & i
& "</a>" & " "
end if
next
%>
<%
' giai phong tai nguyen
rs.Close
set rs = Nothing
Conn.Close
set Conn = Nothing
%>
224
Email: ledduy@ieee.org
Email: ledduy@ieee.org
%>
Cc thuc tnh v phng thc dng thao tc trn th mc:
CreateFolder, DeleteFolder, CopyFolder, MoveFolder, GetFolder,
... V d:
<%
Sub ShowFolderInfo()
Dim fso, fldr, s
' Get instance of FileSystemObject.
Set fso = CreateObject("Scripting.FileSystemObject")
' Get Drive object.
Set fldr = fso.GetFolder("c:")
' Print parent folder name.
Response.Write "Parent folder name is: " & fldr & "<br>"
' Print drive name.
Response.Write "Contained on drive " & fldr.Drive & "<br>"
' Print root file name.
If fldr.IsRootFolder = True Then
L nh Duy - H KHTN Tp. HCM
225
226
Email: ledduy@ieee.org
Email: ledduy@ieee.org
s = ts.ReadLine
Response.Write "File contents = '" & s & "'"
ts.Close
End Sub
Sub ManipFiles
Dim fso, f1, f2, s
Set fso = CreateObject("Scripting.FileSystemObject")
Set f1 = fso.CreateTextFile("c:\testfile.txt", True)
Response.Write "Writing file <br>"
' Write a line.
f1.Write ("This is a test.")
' Close the file to writing.
f1.Close
Response.Write "Moving file to c:\tmp <br>"
' Get a handle to the file in root of C:\.
Set f2 = fso.GetFile("c:\testfile.txt")
' Move the file to \tmp directory.
f2.Move ("c:\tmp\testfile.txt")
Response.Write "Copying file to c:\temp <br>"
' Copy the file to \temp.
f2.Copy ("c:\temp\testfile.txt")
Response.Write "Deleting files <br>"
' Get handles to files' current location.
Set f2 = fso.GetFile("c:\tmp\testfile.txt")
Set f3 = fso.GetFile("c:\temp\testfile.txt")
' Delete the files.
f2.Delete
f3.Delete
Response.Write "All done!"
End Sub
%>
227
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Language" CONTENT="en-us">
<META NAME="GENERATOR" CONTENT="Microsoft
FrontPage 4.0">
<META NAME="ProgId" CONTENT="FrontPage.
Editor.Document">
<TITLE>CDO for NTS -Simple Input Page</TITLE>
</HEAD>
<BODY>
<FORM METHOD="post" action="CDONTS_advInput.asp"
ID=FORM1 NAME="FrontPage_Form1"
ONSUBMIT="return FrontPage_Form1_Validator(this)">
<TABLE BORDER="0" WIDTH="100%">
<TR>
<TD VALIGN="top" ALIGN="left">From:</TD>
<TD VALIGN="top" ALIGN="left">
<P><!-- WEBBOT BOT="Validation"
STARTSPAN S-DISPLAY-NAME="From"
S-DATA-TYPE="String"
B-ALLOW-LETTERS="TRUE"
B-ALLOW-DIGITS="TRUE"
B-ALLOW-WHITESPACE="TRUE"
228
Email: ledduy@ieee.org
Email: ledduy@ieee.org
S-ALLOW-OTHER-CHARS="@."
B-VALUE-REQUIRED="TRUE"
I-MINIMUM-LENGTH="4" --><!-- WEBBOT
BOT="Validation" endspan-->
;<INPUT NAME="txtFrom" SIZE="45"></P>
</TD>
</TR>
<TR>
<TD VALIGN="top" ALIGN="left">To:</TD>
<TD VALIGN="top" ALIGN="left"><!-WEBBOT BOT="Validation" STARTSPAN
S-DISPLAY-NAME="To" S-DATA-TYPE="String"
B-ALLOW-LETTERS="TRUE"
B-ALLOW-DIGITS="TRUE"
S-ALLOW-OTHER-CHARS="@." B-VALUE-REQUIRED="TRUE"
I-MINIMUM-LENGTH="7" --><!-WEBBOT BOT="Validation" ENDSPAN --><INPUT
SIZE="45" ></TD>
</TR>
<TR>
<TD VALIGN="top" ALIGN="left">Cc:</TD>
<TD VALIGN="top" ALIGN="left">
<INPUT NAME="txtCc" SIZE="45"></TD>
</TR>
<TR>
<TD VALIGN="top" ALIGN="left">Bcc:</TD>
<TD VALIGN="top" ALIGN="left">
<INPUT NAME="txtBcc" SIZE="45"></TD>
</TR>
<TR>
<TD VALIGN="top" ALIGN="left">
Subject:</TD>
<TD VALIGN="top" ALIGN="left">
<INPUT NAME="txtSubject" SIZE="45"></TD>
</TR>
<TR>
<TD VALIGN="top" ALIGN="left">
Reply To:</TD>
<TD VALIGN="top" ALIGN="left">
<INPUT NAME="txtReplyTo" SIZE="45"></TD>
</TR>
<TR>
<TD VALIGN="top" ALIGN="left">
Importance:</TD>
<TD VALIGN="top" ALIGN="left">
<INPUT TYPE="radio" NAME="optImportance"
L nh Duy - H KHTN Tp. HCM
VALUE="2">
High
<INPUT TYPE="radio"
CHECKED NAME="optImportance"
VALUE="1">
Normal
<INPUT TYPE="radio"
NAME="optImportance" VALUE="0">Low</TD>
</TR>
<TR>
<TD VALIGN="top" ALIGN="left">
Message:</TD>
<TD VALIGN="top" ALIGN="left">
<TEXTAREA COLS=68 NAME=txtMessage ROWS=9>
Type your message here in text
or HTML format
To use HTML in the body of your message, make sure
to select HTML Body Type and MIME
Encoding</TEXTAREA></TD>
</TR>
<TR>
<TD VALIGN="top" ALIGN="left">
Body Type:</TD>
<TD VALIGN="top" ALIGN="left">
<INPUT TYPE="radio" NAME="optMsgType" VALUE="1"
TABINDEX="1" checked>
MIME
<INPUT TYPE="radio"
NAME="optMsgType" VALUE="0" TABINDEX="2">HTML</TD>
</TR>
<TR>
<TD VALIGN="top" ALIGN="left">
Encoding:</TD>
<TD VALIGN="top" ALIGN="left">
<INPUT TYPE="radio" NAME="optMsgEncode"
VALUE="0">MIME
<INPUT TYPE="radio"
NAME="optMsgEncode" VALUE="1" checked>TEXT</TD>
</TR>
<TR>
<TD VALIGN="top" ALIGN="left"
COLSPAN="2"><FONT FACE="MS Sans Serif"
SIZE=1>Attach File:
<INPUT NAME="txtattfile" TYPE="file"
SIZE="55"></FONT></TD>
229
230
Email: ledduy@ieee.org
Email: ledduy@ieee.org
</TR>
<TR>
<TD VALIGN="top" ALIGN="left"
COLSPAN="2"><FONT FACE="MS Sans Serif"
size="1">Encode
Attachment: </FONT>
<INPUT TYPE="radio"
NAME="optAttEncode" VALUE="0" checked>UUENCODE
<INPUT TYPE="radio"
NAME="optAttEncode" VALUE="2">
<FONT FACE="MS Sans Serif"
size=1>Base 64</FONT></TD>
</TR>
<TR>
<TD VALIGN="top" ALIGN="left"
COLSPAN="2">
<P ALIGN="center">
<INPUT TYPE="submit" VALUE="Send Message" NAME="btnSend"
TABINDEX="1">
<INPUT TYPE="reset" VALUE="
Clear " NAME="btnClear" TABINDEX="2"></P></TD>
</TR>
</TABLE>
</FORM>
</BODY>
</HTML>
</HEAD>
<BODY>
<%
Dim objMsg, strFrom, strTo,
strCc, strBcc, strReplyTo, strBody, _
strSubject, strFileName
Dim lngImportance, lngMsgFormat,
lngMsgEncode, lngAttEncode
strFrom = Trim(Request.Form("txtFrom"))
strTo = Trim(Request.Form("txtTo"))
strCc = Trim(Request.Form("txtCc"))
strBcc = Trim(Request.Form("txtBcc"))
strReplyTo = Trim(Request.Form("txtReplyTo"))
strSubject = Trim(Request.Form("txtSubject"))
strBody = Trim(Request.Form("txtMessage"))
lngImportance = Trim(Request("optImportance"))
lngMsgFormat = Trim(Request("optMsgType"))
lngMsgEncode = Trim(Request("optMsgEncode"))
lngAttEncode = Trim(Request("optAttEncode"))
strFileName = Trim(Request.Form("txtattfile"))
231
232
Email: ledduy@ieee.org
Email: ledduy@ieee.org
10.2. Bo v m asp
bo v cc on m c vit trong cc trang asp, ta dng
mt cng c gi l ScriptEncoder c cung cp bi Microsoft
http://msdn.microsoft.com/scripting/.
V d sau minh ha vic mt on m c vit trong trang asp.
%>
<HR>
Send another message with <A HREF =
"cdonts_advInput.htm">
advanced features</A><BR>
Send another message with <A HREF =
"cdonts_simpleInput.htm">
basic features</A>
</BODY>
</HTML>
233
<HTML>
<HEAD>
<TITLE>Script Encoder Sample Page</TITLE>
<SCRIPT LANGUAGE="JScript">
<!--//
//Copyright 1998 Microsoft Corporation.
//**Start Encode**
function verifyCorrectBrowser(){
if(navigator.appName == "Microsoft Internet Explorer")
if (navigator.appVersion.indexOf ("5.") >= 0)
return(true);
else
return(false);
}
function getAppropriatePage(){
var str1 = "Had this been an actual Web site, a page compatible
with ";
var str2 = "browsers other than ";
var str3 = "Microsoft Internet Explorer 5.0 ";
var str4 = "would have been loaded.";
if (verifyCorrectBrowser())
document.write(str1 + str3 + str4);
else
document.write(str1 + str2 + str3 + str4);
}
//-->
</SCRIPT>
</HEAD>
<BODY onload="getAppropriatePage()">
</BODY>
</HTML>
234
Email: ledduy@ieee.org
Email: ledduy@ieee.org
Bi tham kho
HIN TH HNH NH T C S D
LIU TRONG CC NG DNG WEB
1. Gii thiu
Vic lu tr v hin th hnh nh t CSDL trong cc ng dng
web l cn thit. V d nh cc ng dng qun l h s ca nhn
vin, ngoi thng tin bng vn bn nh H tn, a ch, bng cp,
s rt cn thit nu c thm d liu v nh ca nhn vin. Hay trong
cc ng dng bn hng, bn cnh thng tin v sn phm nh Tn
sn phm, phn loi sn phm, gi c, hnh nh trc quan v sn
phm cng rt cn thit gip cho ngi dng d dng hn khi
chn la,
Thng thng ngi ta dng mt trong hai cch t c
mc ch ny. Cch th nht l lu tr tp tin hnh nh trn mt th
mc ring, trong CSDL ngoi d liu vn bn ch lu ng dn n
tp tin hnh nh. Cch th hai l lu tr c d liu hnh nh v vn
bn trong cng mt bn ghi trong CSDL.
Cch tip cn th nht thng c dng hn v CSDL c kch
thc nh v thao tc hin th kh n gin thng qua tag IMG vi
thuc tnh SRC c gn bng thng tin v ng dn n tp tin
hnh nh c trong CSDL. Hn ch ca cch tip cn ny l i
hi d liu nh phi c lu tr trn webserver hoc mt my
tnh no m webserver c th truy cp c. Trong cc ng
dng m c s d liu c th c sao lu nhiu bn phn tn,
ri ro s xy ra nu cc tp tin hnh nh khng c sao lu theo
ng ng dn sn c.
Cch tip cn th hai do lu tr hnh nh trong CSDL nh l d
liu nh phn nn s dn n hn ch l lm cho kch thc ca
CSDL tng ln ang k. Nhng b li, d liu hnh nh v vn bn
chung mt ni nn c th dng cho cc CSDL c sao lu nhiu
ni. lu tr d liu hnh nh trn cc h qun tr CSDL ta phi
dng cc kiu d liu dng nh phn cho n. V d, trong MS SQL
Server l kiu d liu image, trong MS Access l kiu d liu OLE
Object.
235
236
Email: ledduy@ieee.org
Email: ledduy@ieee.org
%>
Response.BinaryWrite(rs(APP_IMGDATA))
rs.close
set rs = nothing
Conn.close
set Conn = nothing
3. Ti tp tin nh ln CSDL
c th ti cc tp tin d liu ln server, thng thng ta dng
cc component c vit sn h tr cho vic ny. Mt trong
cc component cung cp min ph l aspSmartUpload
(http://www.aspsmart.com/aspSmartUpload/). Hai vn cn lu
khi s dng cc component dng ny l form trong trang dnh cho
ngi dng nhp phi c t thuc tnh ENCTYPE l
multipart/form-data v trang x l upload phi dng i tng Form
ca cc component ly d liu v thay cho Request.Form. Vi
aspSmartUpload ta c th ti ng thi nhiu tp tin ln server, thm
ch c th hn ch kch thc tp tin, kiu tp tin, s c dng
ti. V d sau minh ha vic ti d liu ln CSDL bng cch dng
tp tin upload.htm cho php ngi dng ch nh tp tin cn upload,
tp tin upload.asp dng lu d liu tp tin cn upload vo mt
trng trong bng CSDL hoc lu thnh mt tp tin trong th mc
no :
upload.htm
<H1>aspSmartUpload : Sample </H1>
<HR>
<FORM
method="POST"
enctype="multipart/form-data">
<input type="FILE" name ="FILE1" ><br>
<input type="submit" value="Upload">
</FORM>
237
238
action="upload.asp"
Email: ledduy@ieee.org
upload.asp
<%
' to i tng aspSmartUpload
Set
mySmartUpload
Server.CreateObject("aspSmartUpload.SmartUpload")
' upload tp tin
mySmartUpload.Upload
kt ni vi CSDL
strDSN = "DRIVER=Microsoft Access Driver (*.mdb);DBQ="
ng dn tng i n tp tin CSDL
strDSN = strDSN & Server.MapPath("app_db/db_users.mdb")
set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open strDSN
%>
Email: ledduy@ieee.org
4. Kt lun
=
set rs = Server.CreateObject(ADODB.Recordset)
set rs.ActiveConnection = Conn
rs.Source = app_users
rs.LockType = 3
rs.Open
rs.close
For each file In mySmartUpload.Files
If NOT file.IsMissing then nu tp tin tn ti
rs. AddNew
lu di dng mt field trong CSDL
file.FileToField rs.Fields(APP_IMGDATA)
lu di dng mt tp tin trn th mc ca server
vi ng dn tuyt i
file.SaveAs("c:\temp\" & file.FileName)
lu di dng mt tp tin trn th mc ca server
vi ng dn tng i so vi th mc webroot
file.SaveAs("dbimages/upload"
&
file.FileName)
rs.Update
End if
Next
rs.close
set rs = nothing
Conn.close
set Conn = nothing
239
240
Email: ledduy@ieee.org
Email: ledduy@ieee.org
Bi tham kho
241
242
Email: ledduy@ieee.org
Email: ledduy@ieee.org
end if
%>
3. Kt lun
Login.asp
<%
On Error Resume Next
vUserName = Request.Form(fmUserName)
Thay th du nhy n thnh hai du nhy n trnh li SQL
injection
vUserName = Replace(vUserName, , )
vPassword = Request.Form(fmPassword)
vPassword = Replace(vPassword, , )
243
244
Email: ledduy@ieee.org
Email: ledduy@ieee.org
Bi tham kho
BO V C S D LIU ACCESS
TRONG CC NG DNG WEB
Cc ng dng web s dng CSDL Access thng hay t tp
tin CSDL .mdb vo mt th mc c th truy cp c t web, v d
nh: D:\inetpub\wwwroot\myDB.mdb. iu nguy him nht theo
cch lm thng thng ny l nu ngi dng bit c hay on
c ng dn n tp tin .mdb, h c th ti tp tin CSDL v
v ton b thng tin lu tr trn CSDL b nh cp.
bo v CSDL Access trong cc ng dng web, nn kt hp
cc phng n an ton sau:
245
246
Email: ledduy@ieee.org
Email: ledduy@ieee.org
dng
ng
dn
tng
i:
sFileName = Server.MapPath(/)
tr v gi tr
D:\inetpub\wwwroot
sFileName = Replace(sFileName, wwwroot, private)
sFileName = sFileName & myDB.mdb
Bi tham kho
1. SQL Injection l g?
Vic thit k v a vo hot ng mt website lun i hi cc
nh pht trin phi quan tm n cc vn v an ton, bo mt
nhm gim thiu ti a kh nng b tn cng t cc tin tc. Tuy
nhin, thng thng cc nh pht trin a s tp trung vo cc vn
an ton trong vic chn h iu hnh, h qun tr CSDL,
webserver s chy ng dng, ... V d, ngi ta thng quan tm
nhiu n cc l hng v an ton trn IIS hn l quan tm n cc
on m ca ng dng c tim n cc l hng nghim trng hay
khng. Mt trong s cc l hng ny l SQL injection attack.
SQL injection l mt k thut cho php nhng k tn cng thi
hnh cc cu lnh truy vn SQL bt hp php (khng c ngi
pht trin lng trc) bng cch li dng l hng trong vic kim
tra d liu nhp trong cc ng dng web. Hu qu ca n rt tai hi
v n cho php nhng k tn cng c th thc hin cc thao tc xa,
hiu chnh, do c ton quyn trn c s d liu ca ng dng. Li
ny thng xy ra trn cc ng dng web c d liu c qun l
bng cc h qun tr CSDL nh SQL Server, Oracle, DB2, Sysbase.
Xt mt v d in hnh, thng thng cho php ngi dng
truy cp vo cc trang web c bo mt, h thng thng xy
dng trang ng nhp yu cu ngi dng nhp thng tin v tn
ng nhp v mt khu. Sau khi ngi dng nhp thng tin vo, h
thng s kim tra tn ng nhp v mt khu c hp l hay khng
quyt nh cho php hay t chi thc hin tip.
Trong trng hp ny, ngi ta c th dng 2 trang, mt trang
HTML hin th form nhp liu v mt trang ASP dng x l
thng tin nhp t pha ngi dng. V d:
Login.htm
<form action="ExecLogin.asp" method="post">
L nh Duy - H KHTN Tp. HCM
247
248
Email: ledduy@ieee.org
Email: ledduy@ieee.org
ExecLogin.asp
<%
Dim p_strUsername, p_strPassword, objRS, strSQL
<%
Dim p_lngID, objRS, strSQL
p_lngID = Request("ID")
p_strUsername = Request.Form("txtUsername")
p_strPassword = Request.Form("txtPassword")
If (objRS.EOF) Then
Response.Write "Invalid login."
Else
Response.Write "You are logged in as " & objRS("Username")
End If
SELECT * FROM tblUsers WHERE Username='' or ''='' and Password = '' or ''=''
Cu truy vn ny l hp l v s tr v tt c cc bn ghi ca
tblUsers v on m tip theo x l ngi dng ng nhp bt hp
php ny nh l ngi dng ng nhp hp l.
L nh Duy - H KHTN Tp. HCM
249
DELETE
FROM
tblArticles.
250
Email: ledduy@ieee.org
Email: ledduy@ieee.org
251
252
Email: ledduy@ieee.org
Email: ledduy@ieee.org
Chng 7
NG DNG MINH HA
CA HNG SCH TRC TUYN
TT Thuc tnh
Kiu DL
M t
BOOK_CATID
Number
BOOK_AUTHOR Char(128)
Danh sch tn tc gi
BOOK_PUBID
Number
BOOK_YEAR
Number
BOOK_PIC
Char(255)
ng dn n tp tin lu nh
ba ca cun sch
BOOK_PRICE
Number
Gi tin
Number
nh gi v sch
10 BOOK_RATE
T_CATEGORY
To th mc C:\MyWebSite\BookStore\DB trong
C:\MyWebSite\BookStore, sau to tp tin
BookStoreDB.mdb trong th mc ny
TT
Thuc tnh
Kiu DL
3. Thit k d liu
CAT_ID
CAT_NAME char(64)
Tn ch
CAT_DESC
M t ch
T_BOOK
T_PUB
char(255)
M t
TT Thuc tnh
Kiu DL
M t
TT
Thuc tnh
Kiu DL
M t
BOOK_ID
AutoNumber
PUB_ID
AutoNumber
BOOK_TITLE
Char(255)
Tn sch
PUB_NAME
char(64)
Tn nh xut bn
BOOK_DESC
Memo
Tm tt ni dung sch
253
254
Email: ledduy@ieee.org
Email: ledduy@ieee.org
TT
Thuc tnh
Kiu DL
M t
PUB_ADDR
char(255)
4. Kt ni vi c s d liu (CSDL)
Cc thao tc c bn
<%@CODEPAGE=65001%>
<%Response.Charset = "utf-8"%>
<!--#include file="dbconn.asp"-->
<%
<%
'On Error Resume Next
L nh Duy - H KHTN Tp. HCM
255
256
Email: ledduy@ieee.org
Email: ledduy@ieee.org
sPicPath = "BookPic/"
strSQL = "SELECT * FROM T_BOOK"
Set rs = Conn.Execute(strSQL)
%>
<table width="600" border="1" cellpadding="5" cellspacing="0"
style="border-collapse: collapse" bordercolor="#111111">
<tr align="center">
<td>TT</td>
<td>Tn sch</td>
<td>Tn tc gi</td>
<td>Nm XB</td>
<td>Gi tin</td>
<td>nh ba</td>
</tr>
<%
i=1
do while not rs.EOF
%>
<tr>
<td><%Response.Write i%></td>
<td><%Response.Write rs("BOOK_TITLE")%></td>
<td><%Response.Write rs("BOOK_AUTHOR")%></td>
<td><%Response.Write rs("BOOK_YEAR")%></td>
<td><%Response.Write rs("BOOK_PRICE")%></td>
<td><img src='<%Response.Write sPicPath &
rs("BOOK_PIC")%>'></td>
</tr>
<%
rs.movenext
i=i+1
loop
%>
<%
rs.Close
Set rs = NOTHING
Conn.Close
Set Conn = NOTHING
%>
257
258
Email: ledduy@ieee.org
Email: ledduy@ieee.org
vBookID = 1
L nh Duy - H KHTN Tp. HCM
259
260
Email: ledduy@ieee.org
Email: ledduy@ieee.org
261
9. S dng Cookies
9.1. Nhc li khi nim v Session, Application, Cookies
Nu mt bin c khai bo trong mt trang ASP, n s b hy
ngay mt khi server x l xong trang ny. c th khai bo cc
bin c th s dng chung cho nhiu trang, ta s dng hai i tng
Application v Session.
262
Email: ledduy@ieee.org
Email: ledduy@ieee.org
263
Thuc tnh
Kiu DL
M t
USER_ID
Char(10)
Tn ng nhp ca
ngi dng. Primary
Key
USER_PASSWORD
Char(10)
Mt khu ng nhp
USER_NAME
Char(50)
Tn y ca ngi
dng
USER_EMAIL
Char(30)
a ch email
USER_PHONE
Char(30)
in thoi lin lc
USER_ADDR
Char(255) a ch lin lc
264
Email: ledduy@ieee.org
Email: ledduy@ieee.org
265
266
Email: ledduy@ieee.org
Email: ledduy@ieee.org
else
Response.Write "<p class=txtText>ng nhp thnh cng. Hy
<a href='>lm tip</a>"
Session("LoginOK") = 1
end if
end if
%>
<%
rs.Close
Set rs = NOTHING
Conn.Close
Set Conn = NOTHING
%>
</body>
</html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=utf8">
<title>Nhp mi sch</title>
<style>
<!-.txtText { font-family: Times New Roman; font-size: 12pt; color:
#0000FF; font-weight: bold }
.txtControl { font-family: Arial; font-size: 10pt; color: #0000FF }
-->
</style>
</head>
<%@CODEPAGE=65001%>
<%Response.Charset = "utf-8"%>
<!--#include file="dbconn.asp"-->
<%
vBookTitle = Request("fBOOK_TITLE")
vBookCatID = Request("fBOOK_CATID")
vBookAuthor = Request("fBOOK_AUTHOR")
vBookPubID = Request("fBOOK_PUBID")
vBookYear = Request("fBOOK_YEAR")
<body>
<%
if Session("LoginOK") <> 1 then
267
sPicPath = "BookPic/"
strSQL = "SELECT * FROM T_BOOK WHERE "
strSQL = strSQL & "BOOK_TITLE LIKE" & "'%" & vBookTitle & "%'"
strSQL = strSQL & " AND BOOK_AUTHOR LIKE" & "'%" &
vBookAuthor & "%'"
268
Email: ledduy@ieee.org
Email: ledduy@ieee.org
</form>
</tr>
<%
rs.movenext
i=i+1
loop
%><%
rs.Close
Set rs = NOTHING
Conn.Close
Set Conn = NOTHING
%>
y
...
Session("arBook") = arBook 'cp nht vo bin Session
Trang addtocart.asp s lm nhim v ly BOOK_ID v cp nht
vo mng arBook v NumBook
<%@CODEPAGE=65001%>
<%Response.Charset = "utf-8"%>
<html>
<head>
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=utf8">
269
270
Email: ledduy@ieee.org
Email: ledduy@ieee.org
8">
<title>Xem thng tin gi hng</title>
<style>
<!-.txtText { font-family: Times New Roman; font-size: 12pt; color:
#0000FF; font-weight: bold }
.txtControl { font-family: Arial; font-size: 10pt; color: #0000FF }
-->
</style>
</head>
<body>
<%
' get input data
vBookID = Request("fBOOK_ID")
NumBook = Session("NumBook")
arBook = Session("arBook")
arBook(0, NumBook) = vBookID
arBook(1, NumBook) = 1 ' s lng sch mua mc nh l 1
NumBook = NumBook + 1
Session("NumBook") = NumBook
Session("arBook") = arBook
%>
<%
%>
</body>
</html>
271
<body>
<!--#include file="dbconn.asp"-->
<table width="600" border="1" cellpadding="5" cellspacing="0"
style="border-collapse: collapse" bordercolor="#111111">
<tr align="center">
<td>TT</td>
<td>M sch</td>
<td>Tn sch</td>
<td>Tn tc gi</td>
<td>Nm XB</td>
<td>Gi tin</td>
<td>S lng</td>
</tr>
<%
NumBook = Session("NumBook")
arBook = Session("arBook")
Sum = 0
for i=0 to NumBook-1
%>
<tr>
<td>
<%Response.Write i%> </td>
<td><%Response.Write arBook(0, i)%> </td>
<td>
<%
strSQL = "SELECT * FROM T_BOOK WHERE BOOK_ID=" & arBook(0,
i)
set rs = Conn.Execute (strSQL)
Response.Write rs("BOOK_TITLE")
%> </td>
<td><% Response.Write rs("BOOK_AUTHOR")%> </td>
<td><% Response.Write rs("BOOK_YEAR")%> </td>
<td><% Response.Write rs("BOOK_PRICE")%> </td>
<td><%Response.Write arBook(1, i)
272
Email: ledduy@ieee.org
Email: ledduy@ieee.org
End Sub
</SCRIPT>
</html>
</html>
End Sub
Sub Session_OnStart
Session("LoginOK") = 0
Session("NumBook") = 0
Dim arBook(2, 10)
Session("arBook") = arBook
End Sub
Sub Session_OnEnd
L nh Duy - H KHTN Tp. HCM
Hi: D liu ting Vit nhp trc tip vo CSDL nhng khng
hin th c lc thc thi chng trnh
273
274
Email: ledduy@ieee.org
Email: ledduy@ieee.org
THC HNH
li:
Error Type:
Microsoft OLE DB Provider for ODBC Drivers (0x80004005)
[Microsoft][ODBC Driver Manager] Data source name not found and no
default driver specified
/BookStore/dbconn.asp, line 9
li:
Error Type:
Microsoft OLE DB Provider for ODBC Drivers (0x80004005)
[Microsoft][ODBC Microsoft Access Driver] Operation must use an
updateable query.
/BookStore/addbook.asp, line 27
275
276
Email: ledduy@ieee.org
Email: ledduy@ieee.org
Bi tham kho
Xy dng cc n sau:
Website siu th tng t nh
Amazon (http://www.amazon.com),
Yahoo Shopping (http://shopping.yahoo.com),
Minh Khai Pub (http://www.minhkhaivn.com),
NXB Gio Dc (http://www.nxbgd.com.vn),
VDC Siu th (http://vdcsieuthi.vnn.vn),
ConfidantVCD (http://www.confidantvcd.com),
Nh sch VN (http://www.nhasachvn.com)
1. Mt s khi nim c bn
Dch v thu ch website (web hosting) l khi nim dng ch
qu trnh lm mt website c th truy cp c t Internet. mt
website c th truy cp c t Internet, website phi c t trn
mt my c cu hnh mnh v c kt ni Internet thng xuyn. V
chi ph c c mt my nh vy khng nh nn mi xut hin
cc cng ty cung cp dch v thu ch phc v cho cc cng ty c
nhu cu a website ca mnh ln Internet.
277
278
Email: ledduy@ieee.org
Email: ledduy@ieee.org
279
280
Email: ledduy@ieee.org
Email: ledduy@ieee.org
H tr v t vn an ninh ca h thng
Cc component c h tr sn
iPowerWeb.com
ICDSoft
Globat.com
Tham kho ti
http://www.tophostinfo.com/review1.htm
2.6. H tr k thut
http://www.webhosting-reviews.com/comm1.htm
http://www.practicallynetworked.com/serving/webhost/
http://www.webhostingratings.com/
http://www.findmyhosting.com/
281
282
Email: ledduy@ieee.org
Email: ledduy@ieee.org
MC LC
1. S lc v mng Internet............................................................3
12. http://www.learnasp.com
13. http://www.4guysfromrolla.com
Cu hi ..........................................................................................28
14. http://www.15seconds.com
15. http://asp.superexpert.com
16. http://www.fit.hcmuns.edu.vn/~ldduy/WebCourse
1. Ci t webserver......................................................................37
2. Cu hnh webserver...................................................................43
3. Mt s vn lin quan n an ton ........................................49
4. Mt s cu hi thng gp .......................................................51
Cu hi ..........................................................................................54
Thc hnh .....................................................................................55
CHNG 3: THIT K TRANG WEB .........................................61
1. Gii thiu v HTML....................................................................61
2. Mt s tag c bn ca HTML ....................................................63
3. nh dng bng biu..................................................................69
4. Form v cc thnh phn ca form.............................................71
5. Frame ........................................................................................77
6. Cascading Style Sheet ..............................................................79
Thc hnh .....................................................................................83
283
284
Email: ledduy@ieee.org
Email: ledduy@ieee.org
4. X l cc kt xut d liu.........................................................165
3. Thit k c s d liu..............................................................253
5. Kt ni vi c s d liu .........................................................172
4. Kt ni vi c s d liu .........................................................255
n ...........................................................................................277
4. Cookies....................................................................................213
285
286
Email: ledduy@ieee.org