You are on page 1of 61

WEB TECHNOLOGIES LAB MANUAL

WEEK 1& 2
Aim:
A HTML Program to Implement the Home Page That contains three
frames.
i Top frame contains Logo an! the college "ame an! Lin#s to Home page$
Login Page$ %egistration Page$ &atalog'e page an! &art Page.
ii Left (rame contains At fo'r Lin#s for "a)igation.
iii %ig#t frame contains The pages to Lin# in the left frame m'st *e loa!e!.
P%+,%AM:
in!e-.html
.html/
.hea!/
.title/0HA%AT I"1TIT2TI+"1.3title/
.3hea!/
.frameset cols45167$85 ro9s45:2$;7$85/
.frame name45logo5 scrolling45no5 noresi<e src45logo.html53/
.frame name45hea!er5 scrolling45no5 src45hea!er.html53/
.frame name45home5 scrolling45no5 noresi<e src45home.html53/
.frame name45tmen'5 scrolling45no5 src45tmen'.html53/
.frame name45left5 scrolling45no5 src45left.html53/
.frame name45*o!=5 src45*o!=.html53/
.3frameset/
.3html/
hea!er.html
.center/.mar>'ee/.h1/.*/0HA%AT I"1TIT2TI+"1.3*/.3h1/.3mar>'ee/
.3center/
home.html
.h; align45center5/.a href45*o!=.html5 st=le45te-t?!ecoration:none@5
target45*o!=5/Home.3a/.3h;/
logo.html
.hA align45center5/.img src4Bimages3 logo.gifB/.3hA/
left.html
.center/
.a href45&1E.html5 st=le45te-t?!ecoration:none@5
target45*o!=5/.*/&1E.3*/.3a/.*r/.*r/.*r/.*r/
.a href45E&E.html5 st=le45te-t?!ecoration:none@5
target45*o!=5/.*/E&E.3*/.3a/.*r/.*r/.*r/.*r/
.a href45IT.html5 st=le45te-t?!ecoration:none@5
tmen'.html
.ta*le align45center5/
.t! 9i!th451675 align45left5/.a st=le45te-t?!ecoration:none@5 href45login.html5
target45*o!=5/.*/Login.3*/.3a/.3t!/
.t! 9i!th451675 align45center5/.a st=le45te-t?!ecoration:none@5
href45%egistration.html5 target45*o!=5/.*/%egistration.3*/.3a/.3t!/
.t! 9i!th451675 align45center5/.a st=le45te-t?!ecoration:none@5
href45catalog'e.html5 target45*o!=5/.*/&atalog'e.3*/.3a/.3t!/
.t! 9i!th451675 align45right5/.a st=le45te-t?!ecoration:none@5 href45cart.html5
target45*o!=5/.*/&art.3*/.3a/.3t!/.t!/
.3ta*le/
*o!=.html
.hA align45center5/Welcome to 0IT1W.3hA/
&1E.html
.hA align45center5/&+MP2TE% 1&IE"&E E",I"EE%I",.3hA/
ECE.html
.hA align45center5/Electronics & &omm'nication Engineering.3hA/
IT.html
.hA align45center5/I"(+%MATI+" TE&H"+L+,C.3hA/
login.html
.html/
.hea!/.title/L+,I".3title/
.script t=pe45te-t3Da)ascript5/
f'nction )ali!ateE
F
ifE!oc'ment.getElement0=I!EGi!G.)al'e.length447
F
9in!o9.alertE5IH is re>'ire!I5@
Jelse
ifE!oc'ment.getElement0=I!EGpassG.)al'e.length447
F
9in!o9.alertE5Pass9or! is re>'ire!I5@
Jelse
F
)ar name4!oc'ment.getElement0=I!EGi!G@
9in!o9.alertE5Welcome 5Kname.)al'e@
J
J
.3script/
.3hea!/
.*o!=/
.h; align45center5/L+,I".3h;/
.ta*le align45center5/
.form metho!45post5/
.tr/
.t!/2ser IH:.3t!/
.t!/.inp't t=pe45te-t5 name45i!5 i!45i!5 3/.3t!/
.3tr/
.tr/
.t!/Pass9or!:.3t!/
.t!/.inp't t=pe45pass9or!5 name45pass5 i!45pass5 3/.3t!/
.3tr/
.tr/.t! colspan4525 align45center5/.inp't )al'e45Login5 t=pe45s'*mit5
onclic#45)ali!ateE@5 3/.3t!/
.3tr/
.3ta*le/.3*o!=/.3html/
Registration.html
.html/
.hea!/.title/%egistration.3title/
.script t=pe45te-t3Da)ascript5/
f'nction )ali!ateE
F
9in!o9.alertE5%egistration 1'ccessI5@
J
.3script/
.3hea!/
.*o!=/
.h; align45center5/%egistration.3h;/
.form metho!45post5 action45login.html5/
.ta*le align45center5 height45;675/
.tr/
.t!/"ame:.3t!/
.t!/.inp't t=pe45te-t5 name45name5 3/.3t!/
.3tr/
.tr/
.t!/Pass9or!:.3t!/
.t!/.inp't t=pe45pass9or!5 name45pass5 3/.3t!/
.3tr/.tr/
.t!/E?mail IH:.3t!/
.t!/.inp't t=pe45te-t5 name45email5 3/.3t!/
.3tr/
.tr/
.t!/Phone n'm*er:.3t!/
.t!/.inp't t=pe45te-t5 name45phLno5 3/.3t!/
.3tr/
.tr/
.t!/1e-:.3t!/
.t!/.inp't t=pe45ra!io5 name45se-5 )al'e45male5 3/ Male
.inp't t=pe45ra!io5 name45se-5 )al'e45female5 3/ (emale.3t!/
.3tr/
.tr/
.t!/Hate of 0irth EH M C:.3t!/
.t!/
.select/
.option )al'e4515 name45!5/1.3option/ .option )al'e4525
name45!5/2.3option/
.option )al'e45A5 name45!5/A.3option/ .option )al'e45;5
name45!5/;.3option/
.option )al'e4565 name45!5/6.3option/ .option )al'e45M5
name45!5/M.3option/
.option )al'e45N5 name45!5/N.3option/ .option )al'e45O5
name45!5/O.3option/
.option )al'e45:5 name45!5/:.3option/ .option )al'e45175
name45!5/17.3option/
.option )al'e45125 name45!5/12.3option/ .option )al'e451A5
name45!5/1A.3option/
.option )al'e451;5 name45!5/1;.3option/ .option )al'e45165
name45!5/16.3option/
.option )al'e451M5 name45!5/1M.3option/ .option )al'e451N5
name45!5/1N.3option/
.option )al'e451O5 name45!5/1O.3option/ .option )al'e451:5
name45!5/1:.3option/
.option )al'e45275 name45!5/27.3option/ .option )al'e45215
name45!5/21.3option/
.option )al'e45225 name45!5/22.3option/ .option )al'e452A5
name45!5/2A.3option/
.option )al'e452;5 name45!5/2;.3option/ .option )al'e45265
name45!5/26.3option/
.option )al'e452M5 name45!5/2M.3option/ .option )al'e452N5
name45!5/2N.3option/
.option )al'e452O5 name45!5/2O.3option/ .option )al'e452:5
name45!5/2:.3option/
.option )al'e45A75 name45!5/A7.3option/ .option )al'e45A15
name45!5/A1.3option/
.3select/
.select/
.option )al'e4515 name45m5/1.3option/ .option )al'e4525
name45m5/2.3option/
.option )al'e45A5 name45m5/A.3option/ .option )al'e45;5
name45m5/;.3option/
.option )al'e4565 name45m5/6.3option/ .option )al'e45M5
name45m5/M.3option/
.option )al'e45N5 name45m5/N.3option/ .option )al'e45O5
name45m5/O.3option/
.option )al'e45:5 name45m5/:.3option/ .option )al'e45175
name45m5/17.3option/
.option )al'e45115 name45m5/11.3option/ .option )al'e45125
name45m5/12.3option/
.3select/
.select/
.option )al'e451:OO5 name45=5/1:OO.3option/ .option )al'e451:O:5
name45=5/1:O:.3option/
.option )al'e451::75 name45=5/1::7.3option/ .option )al'e451::15
name45=5/1::1.3option/
.option )al'e451::25 name45=5/1::2.3option/ .option )al'e451::A5
name45=5/1::A.3option/
.3select/
.3t!/
.3tr/
.tr/
.t!/Lang'ages Kno9n:.3t!/
.t!/
.inp't t=pe45chec#*o-5 name45english5 )al'e45english5 3/ English
.inp't t=pe45chec#*o-5 name45tel'g'5 )al'e45tel'g'5 3/ Tel'g'
.inp't t=pe45chec#*o-5 name45hin!i5 )al'e45tel'g'5 3/ Hin!i
.inp't t=pe45chec#*o-5 name45tamil5 )al'e45tamil5 3/ Tamil
.3t!/
.3tr/
.tr/
.t!/A!!ress:.3t!/
.t!/.te-tarea ro9s45;5 cols45A75 name45a!!ress5/.3te-tarea/ .3t!/
.3tr/
.tr/.t! colspan4525 align45center5/.inp't )al'e45%egister5 t=pe45s'*mit5
onclic#45)ali!ateE@5 3/.3t!/
.3tr/
.3ta*le/.3*o!=/.3html/
cataloge.html
.script t=pe45te-t3Da)ascript5/
f'nction )ali!ateE
F
9in!o9.alertE50oo# a!!e! to cartI5@
J
.3script/
.hA align45center5/0oo#s.3hA/
.form action45cart.html5 metho!45post5/
.ta*le align45center5 *or!er4515 9i!th45M675/
.tr/
.th 9i!th451675/"ame.3th/
.th/Logo.3th/
.th/A'thor.3th/
.th/P'*lication.3th/
.th/Price.3th/
.th/&art.3th/
.3tr/
.tr align45center5/
.t!/PML 0i*le.3t!/
.t!/.img src45images3-ml*i*leco)er.Dpg5 9i!th45N65 height45:75 3/.3t!/
.t!/Elliotte %'st= Harol!.3t!/
.t!/H'ngr= Min!s.3t!/
.t!/ Q21.::.3t!/
.t!/.inp't t=pe45s'*mit5 on&lic#45)ali!ateE@5 )al'e45A!! to cart5/.3t!/
.3tr/
.tr align45center5/
.t!/Artificial Intelligence: A Mo!ern Approach .3t!/
.t!/.img src45images3AI.Dpg5 9i!th45O75 height45:75 3/.3t!/
.t!/1t'art R. %'ssell.3t!/
.t!/Princeton Hall.3t!/
.t!/ QAM.7:.3t!/
.t!/.inp't t=pe45s'*mit5 on&lic#45)ali!ateE@5 )al'e45A!! to cart5/.3t!/
.3tr/
.tr align45center5/
.t!/0eginning Ra)a 2.3t!/
.t!/.img src45images3Da)a.Dpg5 9i!th45N65 height45:75 3/.3t!/
.t!/I)or Horton.3t!/
.t!/9ro-.3t!/
.t!/ QO.:6.3t!/
.t!/.inp't t=pe45s'*mit5 on&lic#45)ali!ateE@5 )al'e45A!! to cart5/.3t!/
.3tr/
.tr align45center5/
.t!/HTML6: 2p an! %'nning.3t!/
.t!/.img src45images3HTML6?2p?An!?%'nning.Dpg5 9i!th45N65 height45:75
3/.3t!/
.t!/Mar# Pilgrim.3t!/
.t!/+G%EILLC.3t!/
.t!/ Q1N.::.3t!/
.t!/.inp't t=pe45s'*mit5 on&lic#45)ali!ateE@5 )al'e45A!! to cart5/.3t!/
.3tr/
.3ta*le/
.3form/
cart.html
.h; align45center5/1hopping &art.3h;/
.ta*le align45center5 *or!er4515 9i!th45;775/
.tr/
.th/0oo# "ame.3th/
.th/Price.3th/
.th/S'antit=.3th/
.th/Amo'nt.3th/
.3tr/
.tr align45center5/
.t!/PML 0i*le.3t!/
.t!/ Q21.::.3t!/
.t!/2.3t!/
.t!/ Q;A.:O.3t!/
.3tr/
.tr align45center5/
.t!/HTML6: 2p an! %'nning.3t!/
.t!/ Q1N.::.3t!/
.t!/1.3t!/
.t!/ Q1N.::.3t!/
.3tr/
.tr align45center5/
.t! colspan45A5/Total Amo'nt:.3t!/
.t!/ QM1.:N.3t!/
.3tr/
.3ta*le/
OUT!UT
IN"E#$
HOME $
"E!T$
LOGIN$
REGISTRATION$
CATALOGUE$
CART$
WEE% &
Aim$
A 'a(a Scri)t !rogram to *ali+ate the Registration !age.
!ROGRAM$
.html/
.hea!/
.title/ %egistration.3title/
.script t=pe45te-t3Da)ascript5/
f'nction )ali!ateE
F
re 4 3TUA?Va?<WKQ3@
ifEIre.testE!oc'ment.registration.name.)al'e
F
9in!o9.alertEGIn)ali! "ame.G@
J
ifE!oc'ment.registration.pass.)al'e.length.4M
F
9in!o9.alertEGPass9or! is too shortIG@
J
ifE!oc'ment.registration.phLno.)al'e.length.17
F
9in!o9.alertEGPhone n'm*er not )ali!IG@
J
)ar -4!oc'ment.formsU5registration5WU5email5W.)al'e@
)ar atpos4-.in!e-+fE5X5@
)ar !otpos4-.lastIn!e-+fE5.5@
ifEatpos.1 YY !otpos.atposK2 YY !otposK2/4-.length
F
9in!o9.alertE5In)ali! emailI5@
J
J
.3script/
.3hea!/
.*o!=/
.h; align45center5/%egistration.3h;/
.form name45registration5 metho!45post5 action45%egistration.html5/
.ta*le align45center5 height45;675/
.tr/
.t!/"ame:.3t!/
.t!/.inp't t=pe45te-t5 name45name5 i!45name5 3/.3t!/
.3tr/
.tr/
.t!/Pass9or!:.3t!/
.t!/.inp't t=pe45pass9or!5 name45pass5 i!45pass5 3/.3t!/
.3tr/
.tr/
.t!/E?mail IH:.3t!/
.t!/.inp't t=pe45te-t5 name45email5 3/.3t!/
.3tr/
.tr/
.t!/Phone n'm*er:.3t!/
.t!/.inp't t=pe45te-t5 name45phLno5 3/.3t!/
.3tr/
.tr/
.t!/1e-:.3t!/
.t!/.inp't t=pe45ra!io5 name45se-5 )al'e45male5 3/ Male
.inp't t=pe45ra!io5 name45se-5 )al'e45female5 3/ (emale.3t!/
.3tr/
.tr/
.t!/Hate of 0irth EH M C:.3t!/
.t!/
.select/
.option )al'e4515 name45!5/1.3option/ .option )al'e4525
name45!5/2.3option/
.option )al'e45A5 name45!5/A.3option/ .option )al'e45;5
name45!5/;.3option/
.option )al'e4565 name45!5/6.3option/ .option )al'e45M5
name45!5/M.3option/
.option )al'e45N5 name45!5/N.3option/ .option )al'e45O5
name45!5/O.3option/
.option )al'e45:5 name45!5/:.3option/ .option )al'e45175
name45!5/17.3option/
.option )al'e45e45!5/12.3option/ .option )al'e451A5
name45!5/1A.3option/
.option )al'e451;5 name45!5/1;.3option/ .option )al'e45165
name45!5/16.3option/
.option )al'e451M5 name45!5/1M.3option/ .option )al'e451N5
name45!5/1N.3option/
.option )al'e451O5 name45!5/1O.3option/ .option )al'e451:5
name45!5/1:.3option/
.option )al'e45275 name45!5/27.3option/ .option )al'e45215
name45!5/21.3option/
.option )al'e45225 name45!5/22.3option/ .option )al'e452A5
name45!5/2A.3option/
.option )al'e452;5 name45!5/2;.3option/ .option )al'e45265
name45!5/26.3option/
.option )al'e452M5 name45!5/2M.3option/ .option )al'e452N5
name45!5/2N.3option/
.option )al'e452O5 name45!5/2O.3option/ .option )al'e452:5
name45!5/2:.3option/
.option )al'e45A75 name45!5/A7.3option/ .option )al'e45A15
name45!5/A1.3option/
.3select/
.select/
.option )al'e4515 name45m5/1.3option/ .option )al'e4525
name45m5/2.3option/
.option )al'e45A5 name45m5/A.3option/ .option )al'e45;5
name45m5/;.3option/
.option )al'e4565 name45m5/6.3option/ .option )al'e45M5
name45m5/M.3option/
.option )al'e45N5 name45m5/N.3option/ .option )al'e45O5
name45m5/O.3option/
.option )al'e45:5 name45m5/:.3option/ .option )al'e45175
name45m5/17.3option/
.option )al'e45115 name45m5/11.3option/ .option )al'e45125
name45m5/12.3option/
.3select/
.select/
.option )al'e451:OO5 name45=5/1:OO.3option/ .option )al'e451:O:5
name45=5/1:O:.3option/
.option )al'e451::75 name45=5/1::7.3option/ .option )al'e451::15
name45=5/1::1.3option/
.option )al'e451::25 name45=5/1::2.3option/ .option )al'e451::A5
name45=5/1::A.3option/
3*.3select/
.3t!/
.3tr/
.tr/
.t!/Lang'ages Kno9n:.3t!/
.t!/
.inp't t=pe45chec#*o-5 name45english5 )al'e45english5 3/ English
.inp't t=pe45chec#*o-5 name45tel'g'5 )al'e45tel'g'5 3/ Tel'g'
.inp't t=pe45chec#*o-5 name45hin!i5 )al'e45tel'g'5 3/ Hin!i
.inp't t=pe45chec#*o-5 name45tamil5 )al'e45tamil5 3/ Tamil
.3t!/
.3tr/
.tr/
.t!/A!!ress:.3t!/
.t!/.te-tarea ro9s45;5 cols45A75 name45a!!ress5/.3te-tarea/ .3t!/
.3tr/
.tr/.t! colspan4525 align45center5/
.inp't )al'e45%egister5 t=pe45s'*mit5 on&lic#45)ali!ateE@5 3/
.3t!/.3tr/
.3ta*le/.3*o!=/.3html/
OUTPUT:
WEE% ,
Aim$
To "esign a -e. !age sing CSS/Casca+ing St0le Sheet1.
i1 Use +i22erent 2ont St0les
ii1 Set a Bac3 gron+ 2or .oth )ages an+ single elements
iii1 Control the re)etition o2 image -ith .ac3gron+ re)eat )ro)ert0
i(1 -or3 -ith La0ers
(1 A++ cstomi4e+ crsors
!ROGRAM$
.html/
.hea!/
.title/&11.3title/
.st=le t=pe45te-t3css5/
PF
color:re!@
font?si<e:22p-@
font?famil=:arial@
te-t?!ecoration:'n!erline@
J
AF
color:green@
font?si<e:22p-@
font?famil=:)er!ana@
te-t?!ecoration:none@
J
A:)isite!Fcolor:=ello9J
A:ho)erFcolor:*l'eJ
A:acti)eFcolor:c=anJ
0+HCF*ac#gro'n!?image:'rlEimage.DpgJ
.3st=le/
.*o!=/
.center/
.p/This is normal paragraph tag..3p/
.a href45Z5/This is normal anchor tag..3a/
.*r/.*r/
.* align45center5/La=er1 on top:.3*/
.!i) st=le45position:relati)e@ font?si<e:67p-@ <?in!e-:2@5/LACE%1.3!i)/
.!i) st=le45position:relati)e@ top:?67@ left:6@ color:re!@ font?si<e:O7p-@ <?
in!e-:1@5/LACE%2.3!i)/.*r/
.* align45center5/La=er2 on top:.3*/.*r/
.!i) st=le45position:relati)e@ font?si<e:67p-@ <?in!e-:2@5/LACE%1.3!i)/
.!i) st=le45position:relati)e@ top:?67@ left:6@ color:re!@ font?si<e:O7p-@ <?
in!e-:;@5/LACE%2.3!i)/
.p/Mo'se o)er the 9or!s to change the c'rsor..3p/
.a st=le45c'rsor:a'to5/a'to.3a/ Y
.a st=le45c'rsor:crosshair5/crosshair.3a/ Y
.a st=le45c'rsor:!efa'lt5/!efa'lt.3a/ Y
.a st=le45c'rsor:e?resi<e5/e?resi<e.3a/ Y
.a st=le45c'rsor:help5/help.3a/ Y
.a st=le45c'rsor:mo)e5/mo)e.3a/ Y
.a st=le45c'rsor:n?resi<e5/n?resi<e.3a/ Y
.a st=le45c'rsor:ne?resi<e5/ne?resi<e.3a/ Y
.a st=le45c'rsor:n9?resi<e5/n9?resi<e.3a/ Y
.a st=le45c'rsor:pointer5/pointer.3a/ Y
.a st=le45c'rsor:progress5/progress.3a/ Y
.a st=le45c'rsor:s?resi<e5/s?resi<e.3a/ Y
.a st=le45c'rsor:se?resi<e5/se?resi<e.3a/ Y
.a st=le45c'rsor:s9?resi<e5/s9?resi<e.3a/ Y
.a st=le45c'rsor:te-t5/te-t.3a/ Y
.a st=le45c'rsor:9?resi<e5/9?resi<e.3a/ Y
.a st=le45c'rsor:9ait5/9ait.3a/
.3*o!=/.3html/
OUT!UT$
WEE% 5
Aim$
To Im)lement an #ML 2ile -hich -ill "is)la0 the Boo3 in2ormation
-hich incl+es the 2ollo-ing$
i1 Title o2 the .oo3
ii1 ISBN nm.er
iii1 !.lisher name
i(1 E+ition
(1 !rice
!ROGRAM$
.oo3.+t+$
.IELEME"T *oo#!etails E*oo#K/
.IELEME"T *oo# Etitle$a'thor$is*n$p'*lisher$e!ition$price/
.IELEME"T title EZP&HATA/
.IELEME"T a'thor EZP&HATA/
.IELEME"T is*n EZP&HATA/
.IELEME"T p'*lisher EZP&HATA/
.IELEME"T e!ition EZP&HATA/
.IELEME"T price EZP&HATA/
.oo3.6ml$
.[-ml )ersion451.75 enco!ing452T(?O5[/
.[-ml?st=lesheet t=pe45te-t3-sl5 href45*oo#.-sl5[/
.IH+&TCPE *oo# 1C1TEM 5*oo#.!t!5/
.*oo#!etails/
.*oo#/
.title/PML 0i*le.3title/
.a'thor/Elliotte %'st= Harol!.3a'thor/
.is*n/:ONM6;A217.3is*n/
.p'*lisher/H'ngr= Min!s.3p'*lisher/
.e!ition/;th.3e!ition/
.price/Q21.::.3price/
.3*oo#/
.*oo#/
.title/Artificial Intelligence: A Mo!ern Approach.3title/
.a'thor/1t'art R. %'ssell.3a'thor/
.is*n/:ONM6;A227.3is*n/
.p'*lisher/Princeton Hall.3p'*lisher/
.e!ition/Mth.3e!ition/
.price/QAM.7:.3price/
.3*oo#/
.*oo#/
.title/0eginning Ra)a 2.3title/
.a'thor/I)or Horton.3a'thor/
.is*n/:ONM6;A227.3is*n/
.p'*lisher/9ro-.3p'*lisher/
.e!ition/Ath.3e!ition/
.price/QO.:6.3price/
.3*oo#/
.*oo#/
.title/HTML6: 2p an! %'nning.3title/
.a'thor/Mar# Pilgrim.3a'thor/
.is*n/12A;6MNO:7.3is*n/
.p'*lisher/+G%EILLC.3p'*lisher/
.e!ition/1st.3e!ition/
.price/Q1N.::.3price/
.3*oo#/
.3*oo#!etails/
.oo3.6sl
.[-ml )ersion451.75 enco!ing45I1+?OO6:?15[/
.-sl:st=lesheet )ersion451.75
-mlns:-sl45http:33999.9A.org31:::3P1L3Transform5/
.-sl:template match4535/
.html/.*o!=/
.h2 st=le45color:green@5 align45center5/0oo#s.3h2/.ta*le *or!er4515
align45center5/
.tr st=le45color:gre=@5/
.th/Title.3th/.th/A'thor.3th/.th/I10".3th/
.th/P'*lisher.3th/ .th/E!ition.3th/ .th/Price.3th/.3tr/
.-sl:for?each select45*oo#!etails3*oo#5/.tr/
.t! st=le45font?famil=:G&omic 1ans M1G@ color:re!@5/.-sl:)al'e?of
select45title53/.3t!/
.t! st=le45te-t?transform: capitali<e@ font?9eight:*ol!@5
align45center5/.-sl:)al'e?of select45a'thor53/.3t!/
.t! st=le45color:*l'e5/.-sl:)al'e?of select45is*n53/.3t!/
.t! st=le45color:green@ font?9eight:*ol!@5 align45center5/.-sl:)al'e?of
select45p'*lisher53/.3t!/
.t! st=le45pin#5 align45center5/.-sl:)al'e?of select45e!ition53/.3t!/
.t! st=le45color:)iolet@ font?9eight:*ol!@5/.-sl:)al'e?of select45price53/.3t!/
.3tr/
.3-sl:for?each/
.3ta*le/ .3*o!=/ .3html/
.3-sl:template/
.3-sl:st=lesheet/
OUT!UT
WEE% 7
Aim$
A Sim)le *isal .ean -ith an area 2ille+ -ith Color.
!rogram$
"e(elo)ing a Sim)le Bean Using the B"%$
This section presents an e-ample that sho9s ho9 to !e)elop a simple
0ean an! connect it to other components )ia the 0HK. +'r ne9 component is
calle! the Colors 0ean. It appears as either a rectangle or ellipse that is fille!
9ith a color. A color is chosen at ran!om 9hen the 0ean *egins e-ec'tion. A
p'*lic metho! can *e in)o#e! to change it. Each time the mo'se is clic#e! on
the 0ean$ another ran!om color is chosen. There is one .oolean rea!39rite
propert= that !etermines the shape. The 0HK is 'se! to la= o't an application
9ith one instance of the Colors 0ean an! one instance of the OrBtton 0ean.
The *'tton is la*ele! \&hange.B Each time it is presse!$ the color changes.
HE]EL+PME"T
21I", RA]A
Create a Ne- Bean $
Here are the steps that =o' m'st follo9 to create a ne9 0ean:
1. &reate a !irector= for the ne9 0ean.
2. &reate the Ra)a so'rce fileEs.
A. &ompile the so'rce fileEs.
;. &reate a manifest file.
6. ,enerate a RA% file.
M. 1tart the 0HK.
N. Test.
The follo9ing sections !isc'ss each of these steps in !etail.
&reate a Hirector= for the "e9 0ean Co' nee! to ma#e a !irector= for
the 0ean. To follo9 along 9ith this e-ample$ create
c$8.+38+emo8sn-8+emo8colors. Then change to that !irector=. The &olors an!
+'r0'tton 0eans &reate the 1o'rce (ile for the "e9 0ean The so'rce co!e for
the Colors component is sho9n in the follo9ing listing. It is locate! in the file
Colors.9a(a. The im)ort statement at the *eginning of the file places it in the
pac#age name! sn-.+emo.colors. %ecall from &hapter : that the !irector=
hierarch= correspon!s to the pac#age hierarch=. Therefore$ this file m'st *e
locate! in a s'*!irector= name! sn-8+emo8colors relati)e to the
CLASS!ATH en)ironment )aria*le. The color of the component is !etermine!
*= the pri)ate Color )aria*le color$ an! its shape is !etermine! *= the pri)ate
.oolean )aria*le rectanglar. The constr'ctor !efines an anon=mo's inner
class that e-ten!s MoseA+a)ter an! o)erri!es its mose!resse+/ 1 metho!.
The change/ 1 metho! is in)o#e! in response to mo'se presses. The component
is initiali<e! to a rectang'lar shape of 277 *= 177 pi-els. The change/ 1 metho!
is in)o#e! to select a ran!om color an! repaint the component. The
getRectanglar/ 1 an! setRectanglar/ 1 metho!s pro)i!e access to the one
propert= of this 0ean. The change/ 1 metho! calls ran+omColor/ 1 to choose a
color an! then calls re)aint/ 1 to ma#e the change )isi*le. "otice that the )aint/
1 metho! 'ses the rectanglar an! color )aria*les to !etermine ho9 to present
the 0ean.
33 A simple 0ean.
pac#age s'n9.!emo.colors@
import Da)a.a9t.8@
import Da)a.a9t.e)ent.8@
p'*lic class &olors e-ten!s &an)as F
transient pri)ate &olor color@
pri)ate *oolean rectang'lar@
p'*lic &olorsE F
a!!Mo'seListenerEne9 Mo'seA!apterE F
p'*lic )oi! mo'sePresse!EMo'seE)ent me F
changeE@
J
J@
rectang'lar 4 false@
set1i<eE277$ 177@
changeE@
J
p'*lic *oolean get%ectang'larE F
ret'rn rectang'lar@
J
p'*lic )oi! set%ectang'larE*oolean flag F
this.rectang'lar 4 flag@
repaintE@
J
p'*lic )oi! changeE
F
color 4 ran!om&olorE@
repaintE@
J
pri)ate &olor ran!om&olorE F
int r 4 EintE2668Math.ran!omE@
int g 4 EintE2668Math.ran!omE@
int * 4 EintE2668Math.ran!omE@
ret'rn ne9 &olorEr$ g$ *@
J
p'*lic )oi! paintE,raphics g F
Himension ! 4 get1i<eE@
int h 4 !.height@
int 9 4 !.9i!th@
g.set&olorEcolor@
ifErectang'lar F
g.fill%ectE7$ 7$ 9?1$ h?1@
J
else F
g.fill+)alE7$ 7$ 9?1$ h?1@
J
J
J
&ompile the 1o'rce &o!e for the "e9 0ean &ompile the so'rce co!e to create a
class file. T=pe the follo9ing:
Da)ac &olors.Da)a.
&reate a Manifest (ile Co' m'st no9 create a manifest file. (irst$ s9itch to the
c$8.+38+emo !irector=. This is the !irector= in 9hich the manifest files for the
0HK !emos are locate!. P't the so'rce co!e for =o'r manifest file in the file
colors.m2t.
It is sho9n here:
"ame: s'n93!emo3colors3&olors.class
Ra)a?0ean: Tr'e
This file in!icates that there is one .class file in the RA% file an! that it is a
Ra)a 0ean "otice that the Colors.class file is in the pac#age sn-.+emo.colors
an! in the s'*!irector= sn-8+emo8colors relati)e to the c'rrent !irector=.
,enerate a RA% (ile 0eans are incl'!e! in the Tool0o- 9in!o9 of the 0HK
onl= if the= are in RA% files in the !irector= c$8.+389ars. These files are
generate! 9ith the Dar 'tilit=.
Enter the follo9ing:
Dar cfm ..^Dars^colors.Dar colors.mft s'n9^!emo^colors^8.class
This comman! creates the file colors.9ar an! places it in the !irector=
c$8.+389ars.
ECo' ma= 9ish to p't this in a *atch file for f't're 'se.
1tart the 0HK &hange to the !irector= c$8.+38.ean.o6 an! t=pe rn. This
ca'ses the 0HK to start. Co' sho'l! see three 9in!o9s$ title! Tool0o-$
0ean0o-$ an! Properties. The Tool0o- 9in!o9 sho'l! incl'!e an entr= la*ele!
\&olorsB for =o'r ne9 0ean. &reate an Instance of the &olors 0ean After =o'
complete the prece!ing steps$ create an instance of the Colors 0ean in the
0ean0o- 9in!o9. Test =o'r ne9 component *= pressing the mo'se an=9here
9ithin its *or!ers. Its color imme!iatel= changes. 2se the Properties 9in!o9 to
change the rectanglar propert= from 2alse to tre. Its shape imme!iatel=
changes.
&reate an! &onfig're an Instance of the +'r0'tton 0ean &reate an instance of
the OrBtton 0ean in the 0ean0o- 9in!o9. Then follo9 these steps:
1. ,o to the Properties 9in!o9 an! change the la*el of the 0ean to \&hangeB.
Co' sho'l! see that the *'tton appearance changes imme!iatel= 9hen this
propert= is change!.
2. ,o to the men' *ar of the 0ean0o- an! select E!it Y E)ents Y action Y
actionPerforme!.
A. Mo)e the c'rsor so that it is insi!e the Colors 0ean !ispla= area$ an! clic#
the left mo'se *'tton. Co' sho'l! see the E)ent Target Hialog !ialog *o-.
;. The !ialog *o- allo9s =o' to choose a metho! that sho'l! *e in)o#e! 9hen
this *'tton is clic#e!. 1elect the entr= la*ele! \changeB an! clic# the +K
*'tton.Co' sho'l! see a message *o- appear )er= *riefl=$ stating that the tool
is\,enerating an! compiling a!aptor class.B
6. &lic# on the *'tton. Co' sho'l! see the color change. Co' might 9ant to
e-periment 9ith the Colors 0ean a *it *efore mo)ing on.
+'tp't:
WEE% :
Aim $
Install TOMCAT -e. ser(er an+ A!ACHE.
While installation assign )ort nm.er ;<;< to A!ACHE. Ma3e sre that
these )orts are a(aila.le i.e.= no other )rocess is sing this )ort.
!ROGRAM$
WEE% ;
Aim$
Assme 2or sers ser>=ser?=ser& an+ ser, ha(ing the )ass-or+s )-+>=)-+?=)-+&
an+ )-+, res)ecti(el0. Write a ser(elet 2or +oing the 2ollo-ing.
>. Create a Coo3ie an+ a++ these 2or ser i+@s an+ )ass-or+s to this Coo3ie.
?. Rea+ the ser i+ an+ )ass-or+s entere+ in the Login 2orm /-ee3>1
!ROGRAM$
A++coo3.9a(a
import Da)a.io.I+E-ception@
import Da)a.io.PrintWriter@
import Da)a-.ser)let.1er)letE-ception@
import Da)a-.ser)let.http.&oo#ie@
import Da)a-.ser)let.http.Http1er)let@
import Da)a-.ser)let.http.Http1er)let%e>'est@
import Da)a-.ser)let.http.Http1er)let%esponse@
p'*lic class A!!coo# e-ten!s Http1er)let
F X+)erri!e
p'*lic )oi! ser)iceEHttp1er)let%e>'est re>$Http1er)let%esponse res
thro9s 1er)letE-ception$I+E-ception
F res.set&ontentT=peE5te-t3html5@
PrintWriter o't4res.getWriterE@
&oo#ie c14ne9 &oo#ieE5'sr15$5s'ni5@
&oo#ie p14ne9 &oo#ieE5p9!15$5ani5@
&oo#ie c24ne9 &oo#ieE5'sr25$5a*c5@
&oo#ie p24ne9 &oo#ieE5p9!25$512A5@
&oo#ie cA4ne9 &oo#ieE5'srA5$5!ef5@
&oo#ie pA4ne9 &oo#ieE5p9!A5$5;6M5@
&oo#ie c;4ne9 &oo#ieE5'sr;5$5mno5@
&oo#ie p;4ne9 &oo#ieE5p9!;5$5NO:5@
res.a!!&oo#ieEc1@
res.a!!&oo#ieEp1@
res.a!!&oo#ieEc2@
res.a!!&oo#ieEp2@
res.a!!&oo#ieEcA@
res.a!!&oo#ieEpA@
res.a!!&oo#ieEc;@
res.a!!&oo#ieEp;@
o't.printlnE5&++KIE AHHEH5@
J J
login.html
.html/
.hea!/.title/L+,I".3title/
.3hea!/
.*o!=/
.h; align45center5/L+,I".3h;/
.ta*le align45center5/
.form metho!45get5 action45login5/
.tr/
.t!/2ser IH:.3t!/
.t!/.inp't t=pe45te-t5 name45'sr5 3/.3t!/
.3tr/
.tr/
.t!/Pass9or!:.3t!/
.t!/.inp't t=pe45pass9or!5 name45p9!5 3/.3t!/
.3tr/
.tr/.t! colspan4525 align45center5/.inp't )al'e45Login5 t=pe45s'*mit5
onclic#45)ali!ateE@5 3/.3t!/
.3tr/
.3ta*le/
.3*o!=/
.3html/
cart.html
.h; align45center5/1hopping &art.3h;/
.ta*le align45center5 *or!er4515 9i!th45;775/
.tr/
.th/0oo# "ame.3th/
.th/Price.3th/
.th/S'antit=.3th/
.th/Amo'nt.3th/
.3tr/
.tr align45center5/
.t!/PML 0i*le.3t!/
.t!/ Q21.::.3t!/
.t!/2.3t!/
.t!/ Q;A.:O.3t!/
.3tr/
.tr align45center5/
.t!/HTML6: 2p an! %'nning.3t!/
.t!/ Q1N.::.3t!/
.t!/1.3t!/
.t!/ Q1N.::.3t!/
.3tr/
.tr align45center5/
.t! colspan45A5/Total Amo'nt:.3t!/
.t!/ QM1.:N.3t!/
.3tr/
.3ta*le/
login.9a(a
import Da)a.io.I+E-ception@
import Da)a.io.PrintWriter@
import Da)a-.ser)let.%e>'estHispatcher@
import Da)a-.ser)let.1er)letE-ception@
import Da)a-.ser)let.http.&oo#ie@
import Da)a-.ser)let.http.Http1er)let@
import Da)a-.ser)let.http.Http1er)let%e>'est@
import Da)a-.ser)let.http.Http1er)let%esponse@
p'*lic class login e-ten!s Http1er)let
F 1tring 'ser$pas@
pri)ate %e>'estHispatcher r!@
X+)erri!e
p'*lic )oi! ser)iceEHttp1er)let%e>'est re>$Http1er)let%esponse res
thro9s 1er)letE-ception$I+E-ception
F res.set&ontentT=peE5te-t3html5@
PrintWriter o't4res.getWriterE@
'ser4re>.getParameterE5'sr5@
pas4re>.getParameterE5p9!5@
&oo#ieUW c4re>.get&oo#iesE@
forEint i47@i.c.length@iKK
F ifEEcUiW.get"ameE.e>'alsE5'sr15&&cUiK1W.get"ameE.e>'alsE5p9!15YY
EcUiW.get"ameE.e>'alsE5'sr25 &&cUiK1W.get"ameE.e>'alsE5p9!25YY
EcUiW.get"ameE.e>'alsE5'srA5&& cUiK1W.get"ameE.e>'alsE5p9!A5YY
EcUiW.get"ameE.e>'alsE5'sr;5&& cUiK1W.get"ameE.e>'alsE5p9!;5
F ifEE'ser.e>'alsEcUiW.get]al'eE &&
pas.e>'alsEcUiK1W.get]al'eE
F 33%e>'estHispatcher
r!4re>.get%e>'estHispatcherE53cart.html5@
r!.for9ar!Ere>$res@
Jelse
F o't.printlnE5C+2 A%E "+T A2TH+%I1EH 21E% 5@
33res.sen!%e!irectE53login.html5@
JJJJJ
login>.html
.html/
.hea!/.title/L+,I".3title/
.3hea!/
.*o!=/
.h; align45center5/L+,I".3h;/
.ta*le align45center5/
.form metho!45get5 action45login15/
.tr/
.t!/2ser IH:.3t!/
.t!/.inp't t=pe45te-t5 name45'ser5 3/.3t!/
.3tr/
.tr/
.t!/Pass9or!:.3t!/
.t!/.inp't t=pe45pass9or!5 name45p9!5 3/.3t!/
.3tr/
.tr/.t! colspan4525 align45center5/.inp't )al'e45Login5 t=pe45s'*mit5
onclic#45)ali!ateE@5 3/.3t!/
.3tr/
.3ta*le/
.3*o!=/
.3html/
login>.9a(a
import Da)a.io.I+E-ception@
import Da)a.io.PrintWriter@
import Da)a-.ser)let.8@
p'*lic class login1 e-ten!s ,eneric1er)let
F
pri)ate 1tring
'ser1$p9!1$'ser2$p9!2$'serA$p9!A$'ser;$p9!;$'ser6$p9!6@

X+)erri!e
p'*lic )oi! initE1er)let&onfig sc
F
'ser14sc.getInitParameterE5'sername15@
p9!14sc.getInitParameterE5pass9or!15@
'ser24sc.getInitParameterE5'sername25@
p9!24sc.getInitParameterE5pass9or!25@
'serA4sc.getInitParameterE5'sernameA5@
p9!A4sc.getInitParameterE5pass9or!A5@
'ser;4sc.getInitParameterE5'sername;5@
p9!;4sc.getInitParameterE5pass9or!;5@
J
X+)erri!e
p'*lic )oi! ser)iceE1er)let%e>'est re>$1er)let%esponse resthro9s
1er)letE-ception$I+E-ception
F
res.set&ontentT=peE5te-t3html5@
PrintWriter o't4res.getWriterE@
'ser64re>.getParameterE5'ser5@
p9!64re>.getParameterE5p9!5@
ifEE'ser6.e>'alsE'ser1&&p9!6.e>'alsEp9!1YY
E'ser6.e>'alsE'ser2&&p9!6.e>'alsEp9!2YY
E'ser6.e>'alsE'serA&&p9!6.e>'alsEp9!AYY
E'ser6.e>'alsE'ser;&&p9!6.e>'alsEp9!;
o't.printlnE5.p/ 9elcome to5K'ser6.to2pper&aseE@
else
o't.printlnE5Co' are not a'thori<e! 'ser5@
JJ
-e..6ml$
.9e*?app/
.ser)let/
.ser)let?name/login.3ser)let?name/
.ser)let?class/login.3ser)let?class/
.ser)let?name/login1.3ser)let?name/
.ser)let?class/login1.3ser)let?class/
.ser)let?name/A!!coo#.3ser)let?name/
.ser)let?class/A!!coo#.3ser)let?class/
.init?param/
.param?name/'sername1.3param?name/
.param?)al'e/s'ni.3param?)al'e/
.3init?param/
.init?param/
.param?name/pass9or!1.3param?name/
.param?)al'e/ani.3param?)al'e/
.3init?param/
.init?param/
.param?name/'sername2.3param?name/
.param?)al'e/12A;.3param?)al'e/
.3init?param/
.init?param/
.param?name/pass9or!2.3param?name/
.param?)al'e/;6MN.3param?)al'e/
.3init?param/
.init?param/
.param?name/'sernameA.3param?name/
.param?)al'e/cse.3param?)al'e/
.3init?param/
.init?param/
.param?name/pass9or!A.3param?name/
.param?)al'e/p)psit.3param?)al'e/
.3init?param/
.init?param/
.param?name/'sername;.3param?name/
.param?)al'e/9t.3param?)al'e/
.3init?param/
.init?param/
.param?name/pass9or!;.3param?name/
.param?)al'e/la*.3param?)al'e/
.3init?param/
.3ser)let/
.ser)let?mapping/
.ser)let?name/E-ample.3ser)let?name/
.'rl?pattern/3e-1.3'rl?pattern/
.3ser)let?mapping/
.39e*?app/
OUT!UT$
WEE% A
Aim$
Create a ta.le -hich shol+ contain at least the 2ollo-ing 2iel+s$ name= )ass-or+= emailB
i+= )hone nm.er/these shol+ hol+ the +ata 2rom the registration 2orm1.
Write a 9a(a )rogramCser(letC'S! to connect to that +ata.ase an+ e6tract +ata 2rom the
ta.les an+ +is)la0 them. E6)eriment -ith (arios SDL Eeries.
Insert the +etails o2 the sers -ho register -ith the -e. site= -hene(er a ne- ser clic3s
the s.mit .tton in the registration )age .
!ROGRAM$
Registration.html
.hea!/
.title/%egistration page.3title/
.3hea!/
.*o!=/
.form METH+H45P+1T5 A&TI+"45register5/
.&E"TE%/
.ta*le/
.center/
.tr/ .t!/ 2sername .3t!/
.t!/.inp't t=pe45te-t5 name45'sr5/ .3t!/ .3tr/
.tr/.t!/ Pass9or! .3t!/
.t!/.inp't t=pe45pass9or!5 name45p9!5/ .3t!/ .3tr/
.tr/.t!/Age.3t!/
.t!/.inp't t=pe45te-t5 name45age5/ .3t!/ .3tr/
.tr/ .t!/A!!ress.3t!/
.t!/ .inp't t=pe45te-t5 name45a!!5/ .3t!/ .3tr/
.tr/ .t!/email.3t!/
.t!/ .inp't t=pe45te-t5 name45mail5/ .3t!/ .3tr/
.tr/ .t!/Phone.3t!/
.t!/ .inp't t=pe45te-t5 name45phone5/ .3t!/ .3tr/
.tr/ .t! colspan42 align4center/ .inp't t=pe45s'*mit5 )al'e45s'*mit5/ .3t!/
.3tr/
.3center/
.3ta*le/
.3form/
.3*o!=/
login.html
.html/
.hea!/
.title/Login page.3title/
.3hea!/
.*o!=/ .center/ .ta*le/
.form METH+H45P+1T5 A&TI+"45login5/
.tr/ .t!/ 2sername .3t!/
.t!/.inp't t=pe45te-t5 name45'sr5/.3t!/ .3tr/
.tr/ .t!/ Pass9or! .3t!/
.t!/ .inp't t=pe45pass9or!5 name45p9!5/ .3t!/ .3tr/
.tr/ .t! align4center colspan4525/.inp't t=pe45s'*mit5 )al'e45s'*mit5/.3t!/
.3tr/
.3ta*le/ .3center/
.3form/
.3*o!=/
.3html/
Ini.9a(a
import Da)a-.ser)let.8@
import Da)a.s>l.8@
import Da)a.io.8@
p'*lic class Ini e-ten!s ,eneric1er)let
F pri)ate 1tring 'ser1$p9!1$email1@
p'*lic )oi! ser)iceE1er)let%e>'est re>$1er)let%esponse res thro9s
1er)letE-ception$I+E-ception
F
'ser14re>.getParameterE5'ser5@
p9!14re>.getParameterE5p9!5@
email14re>.getParameterE5email5@
res.set&ontentT=peE5te-t3html5@
PrintWriter o't4res.getWriterE@
tr=
F
&lass.for"ameE5oracle.D!*c.!ri)er.+racleHri)er5@
&onnection con4Hri)erManager.get&onnectionE5D!*c:oracle:thin5$5scott5$5tiger5@
Prepare!1tatement st4con.prepare1tatementE5insert into personal
)al'esE[$[$[$[$[$[5@
st.set1tringE1$'ser1@
st.set1tringE2$p9!1@
st.set1tringEA$5265@
st.set1tringE;$5h=!5@
st.set1tringE6$email1@
st.set1tringEM$5212A;5@
st.e-ec'te2p!ateE@
con.closeE@
J
catchE1SLE-ception s
F o't.printlnE5not fo'n! 5Ks@
J
catchE&lass"ot(o'n!E-ception c
F o't.printlnE5not fo'n! 5Kc@
JJ
J
-e..6ml$
.9e*?app/
.ser)let/
.ser)let?name/init1.3ser)let?name/
.ser)let?class/Ini.3ser)let?class/
.3ser)let/
.ser)let?mapping/
.ser)let?name/init1.3ser)let?name/
.'rl?pattern/3register.3'rl?pattern/
.3ser)let?mapping/
.39e*?app/
OUT!UT$
WEE%B><
Aim$
Write a 'S! -hich +oes the 2ollo-ing 9o.$
Insert the +etails o2 the & or , sers -ho register -ith the -e. site /-ee3A1 .0 sing
registration 2orm. Athenticate the ser -hen he s.mits the login 2orm sing the ser
name an+ )ass-or+ 2rom the +ata.ase / similar to -ee3; instea+ o2 coo3ies1.
!ROGRAM$
login.html
.html/
.hea!/.title/L+,I".3title/
.script t=pe45te-t3Da)ascript5/
.3script/
.3hea!/
.*o!=/
.h; align45center5/L+,I".3h;/
.ta*le align45center5/
.form metho!45get5 action45a'th.Dsp5/
.tr/
.t!/2ser IH:.3t!/
.t!/.inp't t=pe45te-t5 name45i!5 i!45i!5 3/.3t!/
.3tr/
.tr/
.t!/Pass9or!:.3t!/
.t!/.inp't t=pe45pass9or!5 name45pass5 i!45pass5 3/.3t!/
.3tr/
.tr/.t! colspan4525 align45center5/.inp't )al'e45Login5 t=pe45s'*mit5
3/.3t!/
.3tr/
.3ta*le/
.3*o!=/
.3html/
ath.9s)
._Xpage import45Da)a.s>l.8@5_/
.html/
.hea!/
.title/Wee# 17.3title/
.3title/
.3hea!/
.*o!=/
._I1tring 'name$p9!@_/
._
'name4re>'est.getParameterE5'ser5@
p9!4re>'est.getParameterE5p9!5@
tr=
F
&lass.for"ameE5oracle.D!*c.!ri)er.+racleHri)er5@
&onnection
con4Hri)erManager.get&onnectionE5D!*c:oracle:thin5$5scott5$5tiger5@
1tatement st4con.create1tatementE@
%es'lt1et rs4st.e-ec'teS'er=E5select name$pass9or! from personal
9here name4G5K'nameK5G an! pass9or!4G5Kp9!K5G5@
ifErs.ne-tE
F o't.printlnE5A'thori<e! person5@
Jelse
F o't.printlnE52nA'thori<e! person5@
J
con.closeE@
J
catchEE-ception eFo't.printlnE55Ke@J
_/
.3*o!=/
.3html/
Ot)t$
WEE%B>>
Aim$
Create ta.les in the +ata.ase -hich contain the +etails o2 items /.oo3s in or case li3e
Boo3 name = !rice= Dantit0= Amont 11 o2 each categor0. Mo+i20 0or cataloge )age
/-ee3 ?1in sch a -a0 that 0o shol+ connect to the +ata.ase an+ e6tract +ata 2rom
the ta.les an+ +is)la0 them in the cataloge )age sing '"BC.
!ROGRAM$
Retrie(e.html
import Da)a.io.I+E-ception@
import Da)a.io.PrintWriter@
import Da)a.s>l.8@
import Da)a-.ser)let.1er)letE-ception@
import Da)a-.ser)let.http.Http1er)let@
import Da)a-.ser)let.http.Http1er)let%e>'est@
import Da)a-.ser)let.http.Http1er)let%esponse@
p'*lic class %etrie)e e-ten!s Http1er)let
F X+)erri!e
p'*lic )oi! ser)iceEHttp1er)let%e>'est re>$Http1er)let%esponse res
thro9s 1er)letE-ception$I+E-ception
F res.set&ontentT=peE5te-t3html5@
PrintWriter o't4res.getWriterE@
tr=F
&lass.for"ameE5oracle.D!*c.!ri)er.+racleHri)er5@
&onnection
con4Hri)erManager.get&onnectionE5D!*c:oracle:thin5$5scott5$5tiger5@
1tatement s4con.create1tatementE@
%es'lt1et r4s.e-ec'teS'er=E5select 8 from cart5@
o't.printlnE5.center/ .ta*le *or!er41/5@
o't.printlnE5.thea!/ .th/ 0oo# name .3th/ .th/ Price .3th/ .th/S'antit=
.3th/ .th/ Amo'nt .3th/ .3thea!/5@
9hileEr.ne-tE
F o't.printlnE5.tr/ .t!/ 5Kr.get1tringE1K5.3t!/ 5@
o't.printlnE5.t!/ 5Kr.get1tringE2K5.3t!/ 5@
o't.printlnE5.t!/ 5Kr.getIntEAK5.3t!/ 5@
o't.printlnE5.t!/ 5Kr.get1tringE;K5.3t!/ .3tr/5@
J o't.printlnE5.3ta*le/.3center/5@
con.closeE@
J
catchE1SLE-ception s>
F o't.printlnE5s>l e-ception5Ks>@
J
catchE&lass"ot(o'n!E-ception cl
F o't.printlnE5class not fo'n!5Kcl@
JJJ
-e..6ml
<web-app>
<servlet>
<servlet-name>set</servlet-name>
<servlet-class>Cartenter</servlet-class>
</servlet>
<servlet>
<servlet-name>display</servlet-name>
<servlet-class>Retrieve</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>set</servlet-name>
<url-pattern>/enterdata</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>display</servlet-name>
<url-pattern>/display1</url-pattern>
</servlet-mapping>
</web-app>
Ot)t$
WEE%B>?
Aim$
HTT! is a stateless )rotocol. Session is reEire+ to maintain the state. The ser ma0
a++ some items to cart 2rom the catalog )age. He can chec3 the cart )age 2or items. He
ma0 (isit cataloge again an+ select some more items. Here or interest is the selecte+
items shol+ .e a++e+ to ol+er cart rather than ne- cart.
!ROGRAM$
Cataloge.9a(a
import Da)a.io.I+E-ception@
import Da)a.io.PrintWriter@
import Da)a.'til.Arra=List@
import Da)a-.ser)let.1er)let&onfig@
import Da)a-.ser)let.1er)letE-ception@
import Da)a-.ser)let.http.Http1er)let@
import Da)a-.ser)let.http.Http1er)let%e>'est@
import Da)a-.ser)let.http.Http1er)let%esponse@
import Da)a-.ser)let.http.Http1ession@
p'*lic class &atalog'e e-ten!s Http1er)let
F int itemco'nt47@
X+)erri!e
p'*lic )oi! initE1er)let&onfig config thro9s
1er)letE-ception
F s'per.initEconfig@
J X+)erri!e
p'*lic )oi! ser)iceEHttp1er)let%e>'est
re>$Http1er)let%esponse res thro9s
I+E-ception$1er)letE-ception
F res.set&ontentT=peE5te-t3html5@
PrintWriter p94res.getWriterE@
Http1ession hs4re>.get1essionE@
Arra=List cart4EArra=Lisths.getAttri*'teE5cart5@
ifEcartI4n'll
F itemco'nt4cart.si<eE@
J p9.printlnE51elect items in cart5@
p9.printlnE5.*o!=/.fiel!set/.legen!/&atalog'e.3legen!/5
K 5.form action4GcartG metho!4GgetG/5
K 5.inp't t=pe4Gchec#*o-G )al'e4GPML 0i*leG name4G*oo#G/PML
0i*le.3inp't/.*r/5@
p9.printlnE5.inp't t=pe4Gchec#*o-G name4G*oo#G )al'e4GArtificial Intelligence: A
Mo!ern ApproachG/Artificial Intelligence: A Mo!ern Approach.3inp't/.*r/5@
p9.printlnE5.inp't t=pe4Gchec#*o-G name4G*oo#G )al'e4G0eginning Ra)a
2G/0eginning Ra)a 2.3inp't/.*r/5@
p9.printlnE5.inp't t=pe4Gchec#*o-G name4G*oo#G )al'e4GHTML6: 2p an!
%'nningG/HTML6: 2p an! %'nning.3inp't/.*r/5@
p9.printlnE5.inp't t=pe4Gs'*mitG )al'e4GA!! to cartG/5@
p9.printlnE5.3fiel!set/5@
JJ
Cart.9a(a
import Da)a.io.I+E-ception@
import Da)a.io.PrintWriter@
import Da)a.'til.Arra=List@
import Da)a.'til.Iterator@
import Da)a-.ser)let.1er)let&onfig@
import Da)a-.ser)let.1er)letE-ception@
import Da)a-.ser)let.http.Http1er)let@
import Da)a-.ser)let.http.Http1er)let%e>'est@
import Da)a-.ser)let.http.Http1er)let%esponse@
import Da)a-.ser)let.http.Http1ession@
p'*lic class &art e-ten!s Http1er)let
F X+)erri!e
p'*lic )oi! initE1er)let&onfig config thro9s 1er)letE-ception
F s'per.initEconfig@
J X+)erri!e
p'*lic )oi! ser)iceEHttp1er)let%e>'est
re>$Http1er)let%esponse res thro9s
I+E-ception$1er)letE-ception
F res.set&ontentT=peE5te-t3html5@
PrintWriter p94res.getWriterE@
Http1ession hs4re>.get1essionE@
Arra=List cart4EArra=Lisths.getAttri*'teE5cart5@
ifEcart44n'll
F p9.printlnE5"o items in =o'r cart5@
cart4ne9 Arra=ListE@
hs.setAttri*'teE5cart5$cart@
J 1tring itemselecte!UW@
1tring item@
itemselecte!4re>.getParameter]al'esE5*oo#5@
ifEitemselecte!I4n'll
F forEint i47@i.itemselecte!.length@iKK
F item4itemselecte!UiW@
cart.a!!Eitem@
JJ
p9.printlnE5Items in the cart.*r/5@
Iterator it4cart.iteratorE@
9hileEit.has"e-tE
F p9.printlnE5.*r/.*/5Kit.ne-tEK5.3*/5@
J JJ
We..6ml
<web-app>
<servlet>
<servlet-name>Login</servlet-name>
<servlet-class>Login</servlet-class>
<init-param>
<param-name>username</param-name>
<param-value>syam</param-value>
</init-param>
<init-param>
<param-name>password</param-name>
<param-value>syam</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>Login</servlet-name>
<url-pattern>/login.do</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>cat</servlet-name>
<servlet-class>Catalogue</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>cat</servlet-name>
<url-pattern>/Cat</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>cart</servlet-name>
Ot)t$

You might also like