Vous êtes sur la page 1sur 6

First create a database in ms access named shanu In this database create 2 tables namely State state_id state_name 1 Orissa

2 Andhra Pradesh 3 Madhya Pradesh City city_id city_name state_id 1 Bhubaneswar 1 2 Cuttack 1 3 henkanal 1 ! "untur 2 # Bh$%al 3 &$w create a user dsn named shanu' Create a %acka(e my%acka(e and in it &$w %re%are 3 class )iles namely

C$nnecti$n State City

C$nnecti$n'*a+a%acka(e my%acka(e, im%$rt *a+a's-l'., %ublic class c$nnecti$n / %ublic Strin( url 0 1*dbc2$dbc2shanu1, %ublic C$nnecti$n c$n, %ublic Statement st, %ublic +$id (et_c$nnecti$n34 / try/ Class')$r&ame31sun'*dbc'$dbc'5dbcOdbc ri+er14, c$n 0 ri+erMana(er'(etC$nnecti$n3url4, st0c$n'createStatement34, 6catch378ce%ti$n e4/6 6 %ublic +$id cl$se_c$nnecti$n34 / try/

c$n'cl$se34, 6catch378ce%ti$n e4/6 6 6 State.java %acka(e my%acka(e, im%$rt *a+a's-l'., %ublic class state e8tends c$nnecti$n / %ublic 9esultSet (etStates34 / 9esultSet rs 0 null, try/ (et_c$nnecti$n34, rs0 st'e8ecute:uery31select . )r$m state14, 6catch 378ce%ti$n e4/6 return 3rs4, 6 6 city.java%acka(e my%acka(e, im%$rt *a+a's-l'., %ublic class city e8tends c$nnecti$n / %ublic 9esultSet (etCity3Strin( Statename4 / 9esultSet rs 0 null, try/ (et_c$nnecti$n34, rs0 st'e8ecute:uery31select city'city_name as cname )r$m city;state where city'state_id0state'state_id and state'state_name0 <1= Statename=1<1 4, 6catch 378ce%ti$n e4/6 return 3rs4, 6 6

Now create jsp file state_city.jsp

>?@%a(e im%$rt 0 1*a+a'i$'PrintAriter1 ?B >?@%a(e im%$rt01*a+a's-l'.1?B >?@%a(e im%$rt01my%acka(e'.1?B >htmlB >headB >scri%t ty%e01te8tC*a+ascri%t1B )uncti$n sh$wcity3str4 / CCd$cument')$rmsDEF'acti$n01(etcust$mer'*s%G-01=str, CCd$cument')$rmsDEF'submit34, d$cument'(et7lementById31cities14'len(th 0 E, i) 3wind$w'HMIJtt%9e-uest4 /CC c$de )$r I7K=; Fire)$8; Chr$me; O%era; Sa)ari 8mlhtt%0new HMIJtt%9e-uest34, 6 else /CC c$de )$r I7L; I7# 8mlhtt%0new Acti+eHOb*ect31Micr$s$)t'HMIJMMP14, 6 8mlhtt%'$%en31"7M1;1(etcity'*s%G-01=str;true4, 8mlhtt%'$nreadystatechan(e0)uncti$n34 / i) 38mlhtt%'readyState00! NN 8mlhtt%'status002EE4 / +ar 8ml08mlhtt%'res%$nseHMI, +ar ta(s08ml'(et7lementsByMa(&ame31tr14, )$r3+ar i0E,i>ta(s'len(th,i==4 / +ar c$mb$ 0 d$cument'(et7lementById31cities14, +ar $%ti$n 0 d$cument'create7lement31$%ti$n14, $%ti$n'te8t 0 ta(sDiF'child&$desDEF'child&$desDEF'n$deOalue, $%ti$n'+alue 0 ta(sDiF'child&$desDEF'child&$desDEF'n$deOalue,

try / c$mb$'add3$%ti$n; null4, CCStandard 6catch3err$r4/c$mb$'add3$%ti$n4, CC I7 $nly 6 6 CCd$cument'(et7lementById31t8tJint14'innerJMMI08mlht t%'res%$nseMe8t, CCd$cument'(et7lementById31names14'+alue 08mlhtt%'res%$nseMe8t, 6 6 8mlhtt%'send34, 6 >Cscri%tB >CheadB >b$dyB >)$rm name01)$rm11 acti$n011 meth$d01%$st1B >table width01L1L1 b$rder0111B >trB >tdBState &ame >CtdB >tdB >? CCStrin( tables 0 1>tableB>trB>tdBhiii>CtdB>CtrB>CtableB1, CC$ut'%rint3names4, try/ state s 0 new state34, 9esultSet rs0 s'(etStates34, Strin( ss, ?B >select id01c$mb$s1 name01c$mb$s1 $nChan(e01sh$wcity3this'+alue41B >? while3rs'ne8t344 / ss0 rs'(etStrin(324, ?B >$%ti$n +alue0 1>?0 ss ?B1 B>?0ss ?B>C$%ti$nB >? 6 ?B >CselectB

>? 6 catch378ce%ti$n e4/6 ?B >CtdB >CtrB >trB >tdBCity>CtdB >tdB>select id01cities1 name01cities1 B>CtdB >CtrB >CtableB >C)$rmB >Cb$dyB >ChtmlB

&$w create a *s% )ile (etcity'*s% >?@%a(e im%$rt 0 1*a+a'i$'PrintAriter1 ?B >?@%a(e im%$rt01*a+a's-l'.1?B >?@%a(e im%$rt01my%acka(e'city1?B >? Strin( names 0 re-uest'(etParameter31-14, $ut'%rint3names4, try/ city c0 new city34, 9esultSet rs0 c'(etCity3names4, Strin( 8ml01>tableB1, while3rs'ne8t344/ 8ml=01>trB1, 8ml=01>tdB1, 8ml=0rs'(etStrin(314, 8ml=01>CtdB1, 8ml=01>CtrB1, 6 8ml=01>CtableB1, $ut'%rint38ml4, CCc$n'cl$se34, PrintAriter %w0res%$nse'(etAriter34, res%$nse'setC$ntentMy%e31te8tC8ml14, %w'write38ml4, %w')lush34, %w'cl$se34, 6

catch378ce%ti$n e4/6 ?B M$di)y web'8ml as de)ined bel$w>G8ml +ersi$n011'E1 enc$din(01PMFQR1GB >webQa%% +ersi$n012'#1 8mlns01htt%2CC*a+a'sun'c$mC8mlCnsC*a+aee1 8mlns28si01htt%2CCwww'w3'$r(C2EE1CHMISchemaQinstance1 8si2schemaI$cati$n01htt%2CC*a+a'sun'c$mC8mlCnsC*a+aee htt%2CC*a+a'sun'c$mC8mlCnsC*a+aeeCwebQa%%_2_#'8sd1B >ser+letB >ser+letQnameBacti$n>Cser+letQnameB >ser+letQclassB$r('a%ache'struts'acti$n'Acti$nSer+let>Cser+letQclassB >initQ%aramB >%aramQnameBc$n)i(>C%aramQnameB >%aramQ+alueBCA7BQI&FCstrutsQc$n)i('8ml>C%aramQ+alueB >CinitQ%aramB >initQ%aramB >%aramQnameBdebu(>C%aramQnameB >%aramQ+alueB2>C%aramQ+alueB >CinitQ%aramB >initQ%aramB >%aramQnameBdetail>C%aramQnameB >%aramQ+alueB2>C%aramQ+alueB >CinitQ%aramB >l$adQ$nQstartu%B2>Cl$adQ$nQstartu%B >Cser+letB >ser+letQma%%in(B >ser+letQnameBacti$n>Cser+letQnameB >urlQ%atternB.'d$>CurlQ%atternB >Cser+letQma%%in(B >sessi$nQc$n)i(B >sessi$nQtime$utB3E>Csessi$nQtime$utB >Csessi$nQc$n)i(B >welc$meQ)ileQlistB >welc$meQ)ileBstate_city'*s%>Cwelc$meQ)ileB >Cwelc$meQ)ileQlistB >CwebQa%%B &$w run the web a%%licati$n htt%2CCl$calh$st2RER#Ca*a8_%r$*ectC

Centres d'intérêt liés