Title: ColdFusion
1ColdFusion
2ColdFusion Overview
- Server side software
- Uses tags like HTML
- Has necessary programming structures
- Provides SQL access to databases
- One of the most popular server side tools for low
volume applications
3Example
- Simple Student Gradebook
- Authenticate Instructor
- Enter Scores for Students
- Get a Simple Grade Report
- Following is a subset of the whole system
4(No Transcript)
5ColdFusion Pages
- Login.cfm really just an html page
- Getcourse.cfm authenticates instructor, sets
cookie, and presents choices - Doit.cfm allows grade entry or produces grade
report - Updatecourses.cfm updates scores entered
6Login.cfm
lthtmlgt ltbodygt lth3gtEnter your instructor password
herelt/h3gt ltform methodpost actiongetcourse.cfmgt
ltinput namepass typepasswordgt ltinput
typesubmit value"Log in"gt lt/formgt lt/bodygt lt/html
gt
7Getcourse.cfm
lthtmlgt ltbody bgcolorbeigegt ltcfquery
nametestpass datasource"490students"gt select
password from instructor lt/cfquerygt ltcfset
uppassUCase(form.pass)gt ltcfcookie namepassword
valueuppassgt
8Getcourse.cfm
ltcfoutput querytestpassgt ltcfif uppass neq
passwordgt ltpgt lth2gtSorry, but wrong password.
Press back and try again.lt/h2gt ltcfelsegt ltform
methodpost actiondoit.cfmgt lth3gtWhich of the
following do you wish to dolt/h3gt lth4gt ltbrgtlti
nput typeradio namechoice value1gtEnter
grades ltbrgtltinput typeradio namechoice
value2gtGet a grade report ltbrgtltbrgt lt/h4gt
ltinput typesubmit value"Submit
Choice"gt lt/formgt lt/cfifgt lt/cfoutputgt lt/bodygt lt/
htmlgt
9Doit.cfm
lthtmlgt ltbody bgcolorgraygt ltcfquery nametestpass
datasource"490students"gt select password from
instructor lt/cfquerygt ltcfif IsDefined("cookie.pass
word")gt ltcfif cookie.password neq
testpass.passwordgtlt!-- cookie doesn't match
--gt ltpgt lth2gtSorry, but wrong password. Press
back and try again.lt/h2gt
10Doit.cfm
ltcfelsegt ltcfif form.choice eq "1"gt lth3gtEntering
grades...lt/h3gtltbrgt ltcfquery namegrades
datasource490studentsgt select students.name
as sname, tests.name as tname, stud_tests.
score,tests.points,tests.weight, students.ssn,
stud_tests.number from students,tests,stud_tes
ts where students.ssn stud_tests.ssn
and stud_tests.number tests.number
order by students.name,stud_tests.number lt/cfque
rygt
11Doit.cfm
ltform methodpost action"updatescores.cfm"gt ltcfs
et count 0gt ltcfoutput querygrades
group"sname"gt lth2gtsnamelt/h2gt ltcfoutputgt
ltinput typehidden namessn valuessngt ltinput
typehidden nametnumber valuenumbergt ltbrgt
tname ltinput typetext namescore
valuescoregt ltcfset count count
1gt lt/cfoutputgt lt/cfoutputgt ltcfoutputgt ltinput
typehidden namecount valuecountgt lt/cfoutput
gt ltbrgtltbrgtltbrgtltinput typesubmit value"Submit
Scores"gt lt/formgt
12Doit.cfm
ltcfelsegt lth3gtReporting grades...lt/h3gtltbrgt ltcfqu
ery namegrades datasource490studentsgt select
students.name as sname, tests.name as
tname, stud_tests.score,tests.points,tests.weig
ht from students,tests,stud_tests where
students.ssn stud_tests.ssn and
stud_tests.number tests.number order by
students.name,stud_tests.number lt/cfquerygt
13Doit.cfm
ltcfoutput querygrades group"sname"gt lth2gt
snamelt/h2gt ltcfset total 0gt ltcfset number
0gt ltcfoutputgt ltbrgttname score ltcfset
total total (score weight)gt ltcfset
number number weightgt lt/cfoutputgt ltcfset
average NumberFormat(total / number,
"999.99")gt ltbrgtltstronggtAverage score
averagelt/stronggt lt/cfoutputgt
lt/cfifgt lt/cfifgt
14Doit.cfm
ltcfelsegtlt!-- NO Cookie --gt lth2gtSorry, but you
have not logged in. Go to lta href"login.cfm"gt he
relt/agt to do so.lt/h2gt lt/cfifgt lt/bodygt lt/htmlgt
15updatescores.cfm
lthtmlgt ltbodygt ltcfquery nametestpass
datasource"490students"gt select password from
instructor lt/cfquerygt ltcfif IsDefined("cookie.pas
sword")gt ltcfif cookie.password neq
testpass.passwordgtlt!-- cookie doesn't match
--gt ltpgt lth2gtSorry, but wrong password set in
cookie.lt/h2gt
16Updatescores.cfm
ltcfelsegt ltcfset count 1gt ltcfset cc
form.countgt ltcfloop condition "count le
cc"gt ltcfset ssn GetToken(form.ssn,
count, ",")gt ltcfset tnumber
GetToken(form.tnumber, count, ",")gt ltcfset
score GetToken(form.score, count,
",")gt ltcfquery nameupscores
datasource490studentsgt UPDATE Stud_Tests SET
Score score WHERE SSN 'ssn' AND
Number tnumber lt/cfquerygt
ltcfset count count 1gt lt/cfloopgt
lth2gt All done....lt/h2gt
Press the Back key twice for other
choices. lt/cfifgt
17Updatescores.cfm
ltcfelsegtlt!-- NO Cookie --gt lth2gtSorry, but you
have not logged in. Go to lta href"login.cfm"gt he
relt/agt to do so.lt/h2gt lt/cfifgt lt/bodygt lt/htmlgt
18Relational Operators
- IS (EQUAL, EQ)
- IS NOT (NOT EQUAL, NEQ)
- CONTAINS
- DOES NOT CONTAIN
- GRATER THAN (GT)
- LESS THAN (LT)
- GREATER THAN OR EQUAL (GTE)
- LESS THAN OR EQUAL (LTE)
19ColdFusion Components
- Tags (all start with ltcfgt)
- Functions common functions for strings,
numbers, dates, system, etc. - Syntax operators, use of pound signs, function
syntax, etc.
20Documentation Available
On the server via the Administrator Log on (see
product documentation, CFML Language
Reference) Books and manuals available from the
consultant in room 434 OSS Your instructor Your
fellow students