Title: - ASP ??????????????????? Internet Information
13.2 ASP
- ASP ??????????????????? Internet
Information Server (IIS) -
abbreviated from Active Server Pages -
server-side script - can be written by
VBScript or JavaScript - delimiters start
with lt end by gt - comment delimiter is
- case-insensitive
2??????????????????? ASP ???? lt gt
???????????? ?????????????? asp ???????????
lt_at_LANGUAGE????gt ???? lt_at_languagejavascr
iptgt ???? lt_at_languagevbscriptgt
3??????? VBScript
?????????????? ?????? Dim ??????????,
??????????,.... - ???????????????????????????????
?????????????? ?????????? -???????????????????
????????????????? ????????? Reserved word
4 ????????????????? ?????????????????????????
????????????????????? Const ????????????
????????????????????? ??????????????
????????????????????????? Dim
????????????(?????????) ???? Dim MyNum(2)
MyNum(0) 4 MyNum(1) 3
Dim MyNo(2,2) MyNo(0,0) 7
MyNo(0,1) 4
5Operators
- Assignment Operator
?????????????? - Arithmetic Operators
??????? - / ??? ??
??? ??? \ ?????? integer
?????????? Mod Modulo
6 - Comparison Operators ltgt
lt lt gt gt - Logical Operators
Not And Or Xor Eqv Imp - String
Operator ???????????
?????????????????????? ??????? ????
A Hello B World
C A , B
7 ltygt ltbrgt
8Process Control
- Iteration
- - ForNext
- - DoLoop
- Conditional
- - IFThenElse
- - Select Case
9For . Next For counter start to end Step
step instructions
Next lt Dim N For N1 to 5
Response.write("Welcome to ASP ltbrgt" ) Next
gt
10????????
ltHTMLgt ltBODY BGCOLOR"BFFFFF"gt lt Dim total,
n total 0 For n 1 To 10
total total1 Next gt ltH2gt
For...Next lt/H2gtltBRgt Value of total is
nbsplttotalgtltBRgt Value of n is
nbspltngtltBRgt ltHRgt
11lt Dim total1, n1 total1 0 For n1 10
To 0 Step -2 total1 total11
Next gt ltH2gt For...Next countdown lt/H2gt
ltBRgt Value of total is nbsplttotal1gt
ltBRgt Value of n is nbspltn1gt lt/BODYgt lt/HTMLgt
12??????????
13DoLoop ?? 4 ??? Do While, Do Until, Loop While
??? Loop Until ????????????????????????????
False Do While Until condition
.. Loop Do .. Loop While
Until condition
14- ????????
- lt
- Dim total
- total 0
- Do While total lt10
- total total1
- Loop
- gt
- Value of total of Do While ... Loop is nbsp
- lttotalgt ltBRgt
15- ???????? (???)
- lt
- total 0
- Do Until total gt10
- total total1
- Loop
- gt
- Value of total of Do Until...Loop is nbsp
- lttotalgt ltBRgt ltHRgt
16- ???????? (???)
- lt total 0
- Do
- total total1
- Loop While total lt10
- gt
- Value of total of Do .... Loop While is nbsp
- lttotalgt ltBRgt
- lt total 0
- Do
- total total1
- Loop Until total gt10
- gt
- Value of total of Do .... Loop Until is nbsp
- lttotalgt
17If Then Else If condition then
Else If condition-n Then .
Else End If
18- ????????
- if name"Supap" then
- response.write("?????????????????")
- else If name"Sumalee" then
- response.write("????????????????")
- else If name"Sunisa" then
- response.write("????????????????")
- else
- response.write("????????????????????")
- end if
19Select Case Select Case testexpression
Case testexpressionlist
Case Else .
End Select
20- ????????
- Select Case Number
- Case 1,2,3
- response.write("Between 1 And 3")
- Case 4,5,6,7,8
- response.write("Between 4 And 8")
- Case Numbergt8
- response.write("Greater than 8")
- Case else
- response.write("Not positive number")
- end Select
21???????? Procedure Procedure ?? 2 ??????
Subprocedure ??? Function Subprocedure
??????????????????????????????????? ??????????????
?? ??????????????????????????????????? ???????????
???????????? ?????????????????????????? ????????
????????????
22 Sub ????subprocedure(?????????) .. End
Sub ????????????????????? ?
??????????????????? ??????????? Call
????subprocedure(?????????)
23ltHTMLgt ltTitlegtASP Procedurelt/Titlegt
ltBODYgt lt Sub SumVal(a) Dim j, aSum aSum
0 For j1 to a aSum aSum1
Next gt Value of a Sum is nbspltaSumgt lt End
Sub Dim i i 10 Call SumVal(i) gt lt/BODYgt
lt/HTMLgt
24Function ??????? Subprocedure ??????????????? ????
??????????????????????????????????
Function ????????????(?????????) ..
???????????? ???????????????????? End
Function Note ???????????????????????????????????
?????????? ??????????? ??????
????????????(?????????)
25??????????????????????? browser ??? server
Response
Web Server
Request
Client
26????????????????????
- ??????????????????????????????????? GET ??? POST
-
- 1. ??????????????? POST ?????????????????????????
???????? ????????????????????????????????????????
??????????? URL ?????????????????????????????
??????????????????????????????????????????????? - 2. ???????????????????? GET ?????????????????????
?????? URL ???? ??????????????????????????????????
???????????????????? URL ?????????????????????
????????????????????????????????????????????
Address ???????????? - ???? http//www.myweb.com/get.php?namematin
eeage30 -
27?????? 1 ??????? methodpost ltform action
"????form.asp" methodpostgt ???????
Request.Form("???? object ???????????")
Request.Form
Response.write
Web Server
Client
Request.QueryString
?????? 2 ??????? methodget ltform action
"????form.asp" methodgetgt ???????
Request.QueryString(" ???? object ???????????")
28 Object Request ????????????????????????????
? ?????????????????? ???????? 2 ?????? 1.
???????????????????? html ???? methodpost
ltform action "????form.asp" methodpost gt
ltinput typetext name "username"gt
lt/formgt ????????? ????????? ??????
Request.Form("username")
29(1) ??????????????? Request.Form (2)
???????????????????????????? form
Request.Form(element) (3) ??????????????? form
??????????????????????????? ??????? 1 ???
Request.Form(element)(index)
30??????????? 1
????????? Ex01.html ??????????????????????????????
??? ltHTMLgt ltBODYgt ltform action "Ex01.asp"
method postgt Name ltinput type "text "
name "tname" gt ltbrgt ID ltinput
type "text " name "id" gtltbrgt ltinput
typesubmit value "Enter" gt lt/formgt lt/BODYgt
lt/HTMLgt
31????????? Ex01.asp ?????????????????????? ltHTMLgt
ltBODYgt lt Response.write "Data in Form
includes with ltbrgt" Response.write "Name "
Request.Form("tname")
"ltbrgt" Response.write "ID " Request.Form("id")
"ltbrgt" gt lt/BODYgt lt/HTMLgt
32??????????? 2
ltHTMLgt ltBODY BGCOLOR"FFFFF0"gt Please Select
one or more your favorite cities. ltform
action"collform.asp" method postgt ltselect
size3 name"city" MULTIPLEgt
ltOPTIONgtMadridlt/OPTIONgt ltOPTIONgtNew
Yorklt/OPTIONgt ltOPTIONgtSidneylt/OPTIONgt
ltOPTIONgtLondonlt/OPTIONgt lt/selectgt ltinput
typesubmitgt lt/formgt lt/BODYgt lt/HTMLgt
collform.html
33ltUgtForm is lt/UgtltRequest.Formgtltbrgt ltUgtAll value
of Form are lt/Ugt nbspltRequest.Form("city")gt
ltbrgt Each value of Form is lt dim i
For i1 To Request.Form("city").Count gt ltReques
t.Form("city")(i)gt ltbrgt ltNextgt
1
2
3
collform.asp
34???? collform.html
???? collform.asp
35 2. ????????????????????????? methodget
???????????????????????????????? URL
????????? QueryString ltform action
"????form.asp" methodget gt ltinput
typetext name "username" gt
lt/formgt ????????? ????????? ??????
Request.QueryString("username")
36???????? ???? queryst.html
ltHTMLgt ltBODY BGCOLOR"FFFFF"gt Please fill
information to this pagelthrgt ltform
action"queryst.asp" method"get"gt Your name
nbspnbsp ltinput typetext
name"user"gt ltinput type submit value
"OK"gt ltinput type reset value
"cancel"gt lt/formgt lt/BODYgt lt/HTMLgt
37???? queryst.asp
lthtmlgt ltbodygt Welcome lthrgt Thank you
ltRequest.QueryString("user")gt that contact
us.ltbrgt See you.lthrgt lt/bodygt lt/htmlgt
38 QueryString ??????? ????????????????????????
? ?????????? URL ??? page ??????????????????
????? Web Server ?????????????????????????????????
????????
queryst.html
Thank you ltRequest.QueryString("user")gt
39???? qstring.html ltHTMLgt ltBODY
BGCOLOR"FFFFF"gt Please fill information to this
pagelthrgt ltform action"qstring.asp"
method"get"gt Your name nbspnbspltinput
typetext name"user"gtltbrgt Surname
nbspnbspltinput typetext name"sname"gt ltinput
type submit value "OK"gt ltinput type reset
value "Cancel"gt lt/formgt lt/BODYgt lt/HTMLgt
40???? qstring.asp Welcome ltbrgt Thank you
ltRequest.QueryString("user")gtnbspnbsp ltRequ
est.QueryString("sname")gt that contact
us.ltbrgt See you.lthrgt
???????????????????????????? 1 ???????????????????
?????
41- ?????????????????????????? QueryString ????? 3
??????? - 1) ???????????? Address ???????????????????
- 2) ????????? HTML Form ?????? tag
- ltFORMgt lt/FORMgt ????????????????
- property METHOD ???? get
423) ??????? URL ?? property HREF ??? Tag
ltAgt..lt/Agt ?? HTML Page ???? ltA
HREFqstring.asp?namevaluegt a
querystring example lt/Agt
?????????????????? Hyperlink
??????????????????????? ?? page ??? Request
??????????? test.asp ???????? QueryString
namevalue ?????????
43???????????????? QueryString 1) ???????????????
Request.QueryString 2) ??????????????????????
?????? QueryString Request.QueryString(data-
name) 3) ????????????????????????? 1 ???
Request.QueryString(data-name)(index) ???
Request.QueryString(data-name).Count
????????????????????????????
44Object Request ???????????????????????????
???? Request ??? Client ???????? Web Server
Collection ???????????? request
????????????????????? element ???? ? ??????
- Collection QueryString - Collection Form
45Object Response ??????????????????????????
????? Response ??? Web Server ????????????????????
??????????? Browser ??? Client Method
Write ???????????????????????? Web Server
??????????? browser ????????????
Response.Write result
46???????????????????? browser ???? response
Method Redirect Response.Redirect URL
URL ??????? URL ??? page ????????????? browser
???????????????? ????????? page
?????????????????????????? ?????????? path
???????? page ??????????????????????????????????pa
ge ????? ?????? method ???
???????????????????? tag ????? ???????????tag
ltbodygt ??????????????????????? HTTP Header
?????? page ???????????
47lt! method Redirect for response gt ltHTMLgt
ltBODY BGCOLOR"FFFF0F"gt ltH2gt Choose which page
do you wish to display lt/H2gt ltFORM
ACTION"respons2.asp" METHODPOSTgt ltINPUT
TYPERADIO NAME"PageChoice" VALUE"Page1.html"
CHECKEDgt Page Number 1 ltbrgt ltINPUT TYPERADIO
NAME"PageChoice" VALUE"Page2.html"gt Page Number
2 ltbrgt ltINPUT TYPESUBMIT VALUE"Choose
Page"gt nbspnbspltINPUT TYPERESETgt lt/FORMgt lt/BO
DYgt lt/HTMLgt ???? respons2.html
48???? respons2.asp lt Dim strChoice strChoiceRequ
est.Form("PageChoice") Response.Redirect
strChoice gt page1.html
page2.html
ltHTMLgt ltBODYgt ltH1gtThis is PAGE 1lt/H1gt lt/BODYgt lt/HT
MLgt
ltHTMLgt ltBODYgt ltH1gtThis is PAGE 2lt/H1gt lt/BODYgt lt/HT
MLgt
493.3 JSP
- - ???????? JavaServer Pages
- - ??????????????????????????????? HTML, XML
- ??????????????????????
- - ??????????????? Tomcat Apache ??? Java Compiler
- - ???????? James Duncan Davidson ?.?.2000
- ????????????????? Servlet ?????????????? Byte
Code - ??????????????????????????? ??? JSP Source Code
- http//jakarta.apache.org
50Tag for JSP
???????? 3 ????????? scriptlet, expression
??? declaration scriptlet ?????????????????????
??? Java ?????? ??? ?????????????????? lt gt
???? lthtmlgt ltbodygt lt out.println(Now
is ltbrgt) out.println(new
java.util.Date()) gt lt/bodygt lt/htmlgt
51Tag for JSP
expression ?????????????????????????????????? ???
???????? ?????????????????????????? lt
expression gt ???? lthtmlgt ltbodygt ltNow is
ltbrgtgt ltnew java.util.Date()gt lt/bodygt lt/htmlgt
52Tag for JSP
declaration ?????????????????????????????? ??????
???????????????????? lt! declaration
gt ???? lt! public java.util.Date showdate()
return (new java.util.Date())
gt lthtmlgt ltbodygt Now is ltbrgt
ltshowdate()gt lt/bodygt lt/htmlgt
53Comment in JSP
?? 3 ??? ??? - ??? lt - comment -gt
??????????? jsp ????????????? Tag scriptlet,
expression ??? declaration - ????????
JAVA ?????? // ???? / / ?????????
?????????? Tag scriptlet, expression ???
declaration - ??? Tag ??? HTML ??? lt!--
--gt ????????????? Tag scriptlet, expression
??? declaration
543.4 Perl and CGI
Perl - ???????? Practical Extraction and
Report Language - ??????? file .pl - ????????
Larry Wall in 1987 - ?????????? UNIX
?????????? ???????????????? ???????????????
OS ???? ? ??? - ???????????????? C
????????????????????????????????? C
55- Perl
-
- Perl ??????????????????????????????????????????
Internet - ???????? Application ?????????? ? ?????????
- ?????????????????? ??????????????????????????????
?????? - ??????????????????????????????????????????????????
- ????????????? ????????????????
- ??????????????? ?????????????? text file
?????????? - compiler ??? linker ???????????????
?????????????? - ??????????????? Perl Interpreter
- ???? Perl ???????????????????????????? CGI ??????
Unix - ??? Window
http//www.perl.com
56CGI
- ???????? Common Gateway Interface (CGI)
- CGI ?????????????????????????????? web server
?????????? execute ???
????????????????????????? ???? ???? .exe
??????? - ???? CGI ????????????????????
?????????????????????? ???????????????
- ?? web server ????? ? ???????? cgi ??????? ?
??? - CGI ?????????????????????????????
clients ????????? applications ?? Web
server
57CGI
-CGI ????????????????????????????? ????
C/C, Fortran, Perl, Shell Script , VB,
Pascal/Delphi ??????? - ?????????????????????
???? CGI ??????????? OS ??? web server
???????????????????????????????