Vous êtes sur la page 1sur 70

WT Lab Manual

LAB OBJECTIVE

Overview Object Web Technologies Basic Concept of Web Technologies Advance Programming 1) Introduction to object oriented programming concepts- java as an object oriented programming language structures-methods-arra!s 2) Object based and objects oriented programming creating pac"ages-using overloaded constructors-static class variables-data abstraction and information hiding-relation between super class objects and subclass objects composition verses inheritancepol!morphism- d!namic method binding abstract super classes and concrete super classes #inheriting interface-use of inner classes and wrapper classes-$tring to "eni%er and $tring $uffer classes 3) &ole of object oriented programming in designing '(I #'raphs and )ava*+overview of swing- event handling, adapter classes and la!out managers Advance '(I components- )Popup -enus- ).es"topPane- advance la!out managers 4) /0ception handling and multithreading in object oriented programming- When e0ception handling should be used-java e0ception handling # e0ceptions and inheritance-multithreading in java-thread s!nchroni%ation-daemon threads &unnable interface- 1iles and streams in java 5) 2etwor" and .atabase handling through object oriented programming #using )O$C # processing 3ueries-overview of servlet #introduction to networ"ing #establishing a simple server and a client # introduction to &-I # implementing the remote interface Introduction to java application and applets-control

WEEK 1:
Design the following stati web !ages "e#ui"e$ fo" an online boo% sto"e web site& 45 'OME (A)E: The static home page must contain three f"a*es Top frame6 7ogo and the college name and lin"s to 8ome page, 7ogin page, &egistration page, Catalogue page and Cart page 9the description of these pages will be given below5 7eft frame6 At least four lin"s for navigation, which will displa! the catalogue of respective lin"s 1or e g 6 When !ou clic" the lin" +C,E- the catalogue for C,E Boo"s should be displa!ed in the &ight frame &ight frame6 The pages to the lin"s in the left frame must be loaded here Initiall! this page contains description of the web site 'o*e(age&ht*l

:html; :head; :title; Online Boo" $tore:<title; :frameset rows=>*+?,@?> scrolling=>no>; :frame name=>tframe> src=>Title html>; :frameset cols=*+?,A+?>; :frame name=>tframe> src=>7in"s html>; :frame name=>rframe> src=>8ome html>; :<frameset; :<frameset; :<head; :bod!; :<bod!; :<html;

Out(ut:

./ LO)I0 (A)E: Login(age&ht*l

:html; :head; :title; Online Boo" $tore:<title; :<head; :bod! bgcolor=>pin">; :center; :h4;7O'I2:<h4; :form action=>account html>; :table border=>+>; :tr; :hB;:td;(sername6:<td; :td;:input t!pe=>te0t> value=>> name=>t4>;:<td;:<hB; :<tr; :tr; :hB;:td;Password6:<td; :td;:input t!pe=>password> name=>p4>;:<td;:<hB;

:<tr; :tr; :td;:<td; :td;:input t!pe=>submit> value=>$ign In>; :input t!pe=>submit> value=>&eset>;:<td; :<tr; :<table; :<form; :<center; :<bod!; :<html; Out(ut:

WEEK .:
1/ CATOLO)2E (A)E: The catalogue page should contain the details of all the boo"s available in the web site in a table The details should contain the following6 4 $nap shot of Cover Page * Author 2ame B Publisher C Price D Add to cart button Catologue&ht*l

:html; :head; :title;Online Boo" $tore:<title; :<head; :bod! bgcolor=>pin">; :h4;Boo"s:<h4; :ul t!pe=>s3uare> compact; :li;C:<li; :li;CEE:<li; :li;)ava:<li; :li;.B-$:<li; :li;(2IF:<li; :li;WT:<li; :<ul; :<bod!; :<html;

Out(ut:

3/ 4E)I,T4ATIO0 (A)E: Create a Gregistration formGwith the following fields 45 2ame 9Te0t field5 *5 Password 9password field5 B5 /-mail id 9te0t field5 C5 Phone number 9te0t field5 D5 $e0 9radio button5 H5 .ate of birth 9B select bo0es5 I5 7anguages "nown 9chec" bo0es # /nglish, Telugu, 8indi, Tamil5 A5 Address 9te0t area5 4egist"ation(age&ht*l

:html; :head; :title; Online Boo" $tore:<title; :<head;

:bod! bgcolor=>pin">; :center; :h4;&/'I$T&ATIO2:<h4; :table border=>B>; :tr; :hB;:td;2ame6:<td; :td;:input t!pe=>te0t>;:<td; :<tr; :tr; :td;Password6:<td; :td;:input t!pe=>password>;:<td; :<tr; :tr; :td;$e06:<td; :td;:input t!pe=>radio> name=>r4>;-ale :input t!pe=>radio> name=>r4>;1emale:<td; :<tr; :tr; :td;/mail I.6:<td; :td;:input t!pe=>te0t>;:<td; :<tr; :tr; :td;Phone no6:<td; :td;:input t!pe=>te0t>;:<td; :<tr; :tr; :td;Address6:<td; :td; :te0tarea name =>string>;:<te0tarea;:<td; :<tr; :tr; :td;:input t!pe=>submit> value=>$ign In>; :input t!pe=>reset> value=>&eset>;:<td; :<tr; :<table; :<center; :<bod!; :<html;

Out(ut:

5/ (A6ME0T (A)E: (a7*ent(age&ht*l

:html; :head; :title; Online Boo" $tore:<title; :<head; :bod! bgcolor=>pin">; :center; :h4;Card Information:<h4; :table border=>*>; :tr; :hB;:td;$elect Card T!pe6:<td; :td;:select name=> > si%e=>4>; :option value=>t!pe> selected;2one:<opiton; :option value=>credit card>;Credit Card:<opiton; :option value=>master card>;-aster Card:<opiton;

:option value=>debit card>;.ebit Card:<opiton; :<select; :<td; :<tr; :tr; :td;/nter card no6:<td; :td;:input t!pe=>>;:<td; :<tr; :tr; :td;2ame on card6:<td; :td;:input t!pe=>te0t>;:<td; :<tr; :tr; :td;:<td; :td;:input t!pe=>submit> value=>$ign In>; :input t!pe=>reset> value=>&eset>;:<td; :<tr; :<table; :<center; :<bod!; :<html;
Out(ut:

WEEK 1: VALIDATIO0: Write JavaScript to validate the following fields of the above registration page 4 2ame 92ame should contains alphabets and the length should not be less than H characters5 * Password 9Password should not be less than H characters length5 B /-mail id 9should not contain an! invalid and must follow the standard pattern nameJdomain com5 C Phone number 9Phone number should contain 4+ digits onl!5 2ote6 Kou can also validate the login page with these parameters 4egiste"Vali$ate&ht*l

:html; :head; :title; Online Boo" $tore:<title; :script language=>javascript>; :L-function validate95 M var uname=document get/lementB!Id9>name>5 valueN var pass=document get/lementB!Id9>pwd>5 valueN var emid=document get/lementB!Id9>eid>5 valueN

var phno=document get/lementB!Id9>pno>5 valueN var date=document get/lementB!Id9>date>5 valueN var month=document get/lementB!Id9>month>5 valueN var !ear=document get/lementB!Id9>!ear>5 valueN var addr=document get/lementB!Id9>addr>5 valueN var emsg=>>N var unameOre=new &eg/0p9>PQa-%A-RSMC,TU>5N var passOre=new &eg/0p9>PQa-%A-R+-VSMH,TU>5N var emidOre=new &eg/0p9>WbQa-%A-R+-V O-SEJQa-%A-R+-VSEW Qa%A-RSM*,HTWb>5N var phnoOre=new &eg/0p9>PQ+-VSM4+TU>5N var addrOre=new &eg/0p9>PQa-%A-R+-V ,-<SU>5N if9uname==>>5 emsgE=>name cant be empt!Wn>N else if9uname match9unameOre5==null5 emsgE=>name must contain onl! alphabetsWn>N if9pass==>>5 emsgE=>password cant be empt!Wn>N else if9pass match9passOre5==null5 emsgE=>error in passwordWn>N if9emid==>>5 emsgE=>email id cant be empt!Wn>N else if9emid match9emidOre5==null5 emsgE=>enter valid email idWn>N if9phno==>>5 emsgE=>phno cant be empt!Wn>N else if9phno match9phnoOre5==null5 emsgE=>enter valid phnoWn>N if9addr==>>5 emsgE=>address cant be empt!Wn>N else if9addr match9addrOre5==null5 emsgE=>enter valid addressWn>N if9date==>da!> XX month==>month> XX !ear==>!ear>5 emsgE=>select correct .OB>N if9emsgL=>>5 M alert9emsg5N

return falseN T T --; :<script; :<head; :bod! bgcolor=>pin">; :form action=>success html> on$ubmit=>return validate95> method=>post>; :center; :h4;&/'I$T&ATIO2:<h4; :table border=>+>; :tr; :hB;:td;2ame6:<td; :td;:input t!pe=>te0t> id=>name>;:<td; :<tr; :tr; :td;Password6:<td; :td;:input t!pe=>password> id=>pwd>;:<td; :<tr; :tr; :td;/mail I.6:<td; :td;:input t!pe=>te0t> id=>eid>;:<td; :<tr; :tr; :td;Phone no6:<td; :td;:input t!pe=>te0t> id=>pno>;:<td; :<tr; :tr; :td;$e06:<td; :td;:input t!pe=>radio> name=>se0> id=>se0> value=>male> chec"ed;-ale :input t!pe=>radio> name=>se0> id=>se0> value=>female>;1emale :<td; :<tr; :tr; :td;.ate of Birth6:<td; :td;:select name=>date> si%e=>4> id=>date>; :option value=>da!> selected;.a!:<opiton; :option value=>4>;+4:<opiton; :option value=>*>;+*:<opiton; :option value=>B>;+B:<opiton; :option value=>C>;+C:<opiton; :option value=>D>;+D:<opiton; :option value=>H>;+H:<opiton;

:option value=>I>;+I:<opiton; :option value=>A>;+A:<opiton; :option value=>V>;+V:<opiton; :option value=>4+>;4+:<opiton; :option value=>44>;44:<opiton; :option value=>4*>;4*:<opiton; :option value=>4B>;4B:<opiton; :option value=>4C>;4C:<opiton; :option value=>4D>;4D:<opiton; :option value=>4H>;4H:<opiton; :option value=>4I>;4I:<opiton; :option value=>4A>;4A:<opiton; :option value=>4V>;4V:<opiton; :option value=>*+>;*+:<opiton; :option value=>*4>;*4:<opiton; :option value=>**>;**:<opiton; :option value=>*B>;*B:<opiton; :option value=>*C>;*C:<opiton; :option value=>*D>;*D:<opiton; :option value=>*H>;*H:<opiton; :option value=>*I>;*I:<opiton; :option value=>*A>;*A:<opiton; :option value=>*V>;*V:<opiton; :option value=>B+>;B+:<opiton; :option value=>B4>;B4:<opiton; :<select; :select name=>month> si%e=>4> id=>month>; :option value=>month> selected;-onth:<opiton; :option value=>4>;)an:<opiton; :option value=>*>;1eb:<opiton; :option value=>B>;-ar:<opiton; :option value=>C>;Apr:<opiton; :option value=>D>;-a!:<opiton; :option value=>H>;)un:<opiton; :option value=>I>;)ul:<opiton; :option value=>A>;Aug:<opiton; :option value=>V>;$ep:<opiton; :option value=>4+>;Oct:<opiton; :option value=>44>;2ov:<opiton; :option value=>4*>;.ec:<opiton; :<select; :select name=>!ear> si%e=>4> id=>!ear>; :option value=>!ear> selected;Kear:<opiton; :option value=>4>;4VA+:<opiton;

:option value=>*>;4VA4:<opiton; :option value=>B>;4VA*:<opiton; :option value=>C>;4VAB:<opiton; :option value=>D>;4VAC:<opiton; :option value=>H>;4VAD:<opiton; :option value=>I>;4VAH:<opiton; :option value=>A>;4VAI:<opiton; :option value=>V>;4VAA:<opiton; :option value=>4+>;4VAV:<opiton; :option value=>44>;4VV+:<opiton; :option value=>4*>;4VV4:<opiton; :option value=>4B>;4VV*:<opiton; :option value=>4C>;4VVB:<opiton; :option value=>4D>;4VVC:<opiton; :option value=>4H>;4VVD:<opiton; :option value=>4I>;4VVH:<opiton; :option value=>4A>;4VVI:<opiton; :option value=>4V>;4VVA:<opiton; :option value=>*+>;4VVV:<opiton; :option value=>*4>;*+++:<opiton; :option value=>**>;*++4:<opiton; :option value=>*B>;*++*:<opiton; :option value=>*C>;*++B:<opiton; :option value=>*D>;*++C:<opiton; :<select; :<td :<tr; :tr; :td;Address6:<td; :td; :te0tarea name =>string> rows=>D> cols=>*+> id=>addr>;:<te0tarea;:<td; :<tr; :tr; :td;:br;:<td; :<tr; :tr; :td align=>left>;:input t!pe=>submit> value=>$ign In>;:<td; :td align=>center>;:input t!pe=>reset> value=>&eset>;:<td; :<tr; :<table; :<center; :<form; :<bod!; :<html;

Out!ut:

Wee%836 .esign a web page using C,, 9Cascading ,t!le ,heets/ which includes the following6 45 (se different font, st!les6 In the st!le definition !ou define how each selector should wor" 9font, color etc 5 Then, in the bod! of !our pages, !ou refer to these selectors to activate the st!les

,sheet1&ht*l :html; :head;:title;Cascading $t!le $heets:<title; :st!le t!pe=>te0t<css>; h* M border-color6voiletN border-st!le6grooveN border-width6thic"N margin-left6BD?N margin-right6BD?N color6indigoN T

p M color6Y*B*BAeN font-st!le6italicN font-si%e64*ptN T b headline M color6redN font-si%e6**p0N font-famil!6corsiveN te0t-decoration6underlineN T 0lin" M cursor6crosshairN color6brownN T hlin" M cursor6helpN color6purpleN T :<st!le; :<head; :bod!; :center; :h*;Cascading $t!le $heets:<h*; :b class=>headline>;This is heading st!leL:<b; :br; :a href=> html> class=>0lin">;:br;C&O$$ 7I2Z:br;:<a; :br; :a href=> html> class=>hlin">;8/7P 7I2Z:<a; :br; :p;The sentence with no st!lesLLL:<p; :<center; :<bod!; :<html; Out!ut:

*5 $et a bac"ground image for both the page and single elements on the page ,sheet.&ht*l

:html; :head;:title;Cascading $t!le $heets:<title; :st!le t!pe=>te0t<css>; h* M border-color6voiletN border-st!le6grooveN border-width6thic"N margin-left6BD?N margin-right6BD?N color6whiteN bac"ground-image6url9$unset jpg5N T bod! M bac"ground-image6url9Blue hills jpg5N T p M color6Y*B*BAeN font-st!le6italicN font-si%e64*ptN T b headline M color6redN

font-si%e6**p0N font-famil!6corsiveN te0t-decoration6underlineN T 0lin" M cursor6crosshairN color6brownN T hlin" M cursor6helpN color6purpleN T :<st!le; :<head; :bod!; :center; :h*;Cascading $t!le $heets:<h*; :b class=>headline>;This is heading st!leL:<b; :br; :a href=> html> class=>0lin">;:br;C&O$$ 7I2Z:br;:<a; :br; :a href=> html> class=>hlin">;8/7P 7I2Z:<a; :br; :p;The sentence with no st!lesLLL:<p; :<center; :<bod!; :<html; Out!ut:

B5 Control the repetition of the image with the bac"ground-repeat propert! As bac"ground-repeat6 repeat Tiles the image until the entire page is filled, just li"e an ordinar! bac"ground image in plain 8T-7 ,sheet1&ht*l

:html; :head;:title;Cascading $t!le $heets:<title; :st!le t!pe=>te0t<css>; center M bac"ground-image6url9$unset jpg5N border-color6blac"N border-width6thic"N margin-left64D?N margin-right64D?N T h* M border-color6voiletN border-st!le6grooveN border-width6thic"N margin-left6*+?N margin-right6*+?N color6whiteN bac"ground-image6url9Picture4 emf5N T bod! M bac"ground-image6url9Blue hills jpg5N T p M color6Y*B*BAeN font-st!le6italicN font-si%e64*ptN T b headline M color6redN font-si%e6**p0N font-famil!6corsiveN

te0t-decoration6underlineN T 0lin" M cursor6crosshairN color6brownN T hlin" M cursor6helpN color6purpleN T :<st!le; :<head; :bod!; :center; :h*;Cascading $t!le $heets:<h*; :b class=>headline>;This is heading st!leL:<b; :br; :a href=> html> class=>0lin">;:br;C&O$$ 7I2Z:br;:<a; :br; :a href=> html> class=>hlin">;8/7P 7I2Z:<a; :br; :p;The sentence with no st!lesLLL:<p; :<center; :<bod!; :<html; Out!ut:

C5 .efine st!les for lin"s as A6lin" A6visited A6active A6hover D5 Wor" with la!ers H5 Add a customi%ed cursor Wee%8:6 Write an F-7 file which will displa! the Boo" information which includes the following6 45 Title of the boo" *5 Author 2ame B5 I$B2 number C5 Publisher name D5 /dition H5 Price Write a .ocument T!pe .efinition 9.T.5 to validate the above F-7 file .ispla! the F-7 file as follows The contents should be displa!ed in a table The header of the table should be in color '&/K And the Author names column should be displa!ed in one color and should be capitali%ed and in bold (se !our own colors for remaining columns (se F-7 schemas F$7 and C$$ for the above purpose

boo%sinfo&;*l

:[0ml version=>4 +>[; :[0ml6st!lesheet t!pe=>te0t<0sl> href=>boo"s 0sl>[; :boo"info; :boo" isbn=>VVDC>; :title;web technologies:<title; :author;cris bates:<author; :publisher;winte":<publisher; :edition;*:<edition; :price;*AD V+:<price; :<boo"; :boo" isbn=>VVDD>; :title;how to program www:<title; :author;dietel dietel:<author; :publisher;pearson education:<publisher; :edition;*:<edition; :price;CV+ V+:<price; :<boo"; :boo" isbn=>VVDH>; :title;Information securit!:<title; :author;wiliam stallings:<author; :publisher;pearson education:<publisher; :edition;B:<edition; :price;BAD CD:<price; :<boo"; :boo" isbn=>VVDI>; :title;2etwor" programming:<title; :author;' ) Zowals"i:<author; :publisher;$pringer:<publisher; :edition;C:<edition; :price;DB+ V+:<price; :<boo"; :<boo"info; boo%s&;*l :[0ml version=>4 +>[; :0sl6st!lesheet version=>4 +> 0mlns60sl=>http6<<www wB org<4VVV<F$7<Transform>; :0sl6output method=>html> omit-0ml-declaration=>no> doct!pe-s!stem=>hA******> doct!pepublic=>hA444444><; :0sl6template match=><>;

:html 0mlns=>hABBBBBB>; :head; :title;boo"s information:<title; :<head; :bod!; :h4; Boo"s Information:<h4; :table border=>4> bgcolor=>c!an>; :thead; :tr bgcolor=>gra!>; :th;I$B2:<th; :th;TIT7/:<th; :th;A(T8O&:<th; :th;P(B7I$8/&:<th; :th;/.ITIO2:<th; :th;P&IC/:<th; :<tr; :<thead; :0sl6for-each select=>boo"info<boo">; :tr; :td bgcolor=>pin">;:0sl6value-of select=>Jisbn><;:<td; :td bgcolor=>green>;:0sl6value-of select=>title><;:<td; :td;:b;:0sl6value-of select=>author><;:<b;:<td; :td bgcolor=>blue>;:0sl6value-of select=>publisher><;:<td; :td bgcolor=>red>;:0sl6value-of select=>edition><;:<td; :td bgcolor=>!ellow>;:0sl6value-of select=>price><;:<td; :<tr; :<0sl6for-each; :<table; :<bod!; :<html; :<0sl6template; :<0sl6st!lesheet;

Out(ut:

Wee%85: VI,2AL BEA0,: Create a simple visual bean with a area filled with a color The shape of the area depends on the propert! shape If it is set to true then the shape of the area is $3uare and it is Circle, if it is false The color of the area should be changed d!namicall! for ever! mouse clic" The color should also be changed if we change the color in the Gpropert! window G

olo"s&<a=a pac"age sunw demo colorsN import java awt @N import java awt event @N public class colors e0tends Canvas M transient private Color colorN private boolean rectangularN public colors95 M add-ouse7istener9new -ouseAdapter95M public void mousePressed9-ouse/vent me5 M change95N TT5N

rectangular=falseN set$i%e9*++,4++5N change95N T public boolean get&ectangular95 M return rectangularN T public void set&ectangular9boolean flag5 M this rectangular=flagN repaint95N T public void change95 M color=randomColor95N repaint95N T private Color randomColor95 M int r=9int59*DD@-ath random955N int g=9int59*DD@-ath random955N int b=9int59*DD@-ath random955N return new Color9r,g,b5N T public void paint9'raphics g5 M .imension d=get$i%e95N int h=d heightN int w=d widthN g setColor9color5N if9rectangular5 M g fill&ect9+,+,w-4,h-45N T else M g fillOval9+,+,w-4,h-45N T

T T

olo"s&t;t 9*anifest file/ )ava-Bean6 True 2ame6 sunw<demo<colors<colors class Out!ut:

Wee%8>6 45 Install TO-CAT web server and APAC8/ While installation assign port number C+C+ to TO-CAT and A+A+ to APAC8/ -a"e sure that these ports are available i e , no other process is using this port

*5 Access the above developed static web pages for boo"s web site, using these servers b! putting the web pages developed in wee"-4 and wee"-* in the document root

a/ Installation of A!a he To* at 5&?


45 .ownload the bac"up program of Apache Tomcat H + from Apache website .ouble clic" on it to start the installation

*5 Then it will displa! some description about the installation Clic" ne0t to continue

B5 Then it will displa! the list of components to be installed .on\t change an!thing clic" ne0t to continue

C5 Then it will displa! the installation director! Clic" ne0t to continue

D5 /nter the port number as A+A+ and give proper username and password Clic" ne0t to continue

H5 )ava ]irtual -achine will be automaticall! detected b! the Installer, once !ou have installed the ).Z software prior to the installation of this web server software

I5 Then the installer finishes its installation Clic" on finish to complete the installation

b/ (ath setting fo" se"=let8a!i&<a"


45 &ight clic" on m! computer then select properties

*5 Then under Advanced tab select /nvironment variables

B5 clic" on new then enter ]ariable name as classpath and enter ]ariable value as the following C6WProgram 1ilesWApache $oftware 1oundationWTomcat H +WlibWservlet-api jarN N

C5 Clic" on OZ to complete the $ettings

/ Testing the To* at Web ,e"=e"&

45 Clic" on $tart-enu -; Programs -; Apache Tomcat H + -; Configure Tomcat

*5 Clic" on start to start the Tomcat service

B5 Then open the Web browser and enter the following in the address to open tomcat homepage http6<<localhost6A+A+

C5 Then clic" on Tomcat -anager and provide the username and password to get into the application managers page

Wee%8@: 2se" Authenti ation: Assume four users user4, user*, userB and userC having the passwords pwd4, pwd*, pwdB and pwdC respectivel! Write a servelet for doing the following 4 Create a Coo"ie and add these four user id\s and passwords to this Coo"ie * &ead the user id and passwords entered in the 7ogin form 9wee"45 and authenticate with the values 9user id and passwords5 available in the coo"ies If he is a valid user9i e , user-name and password match5 !ou should welcome him b! name9user-name5 else !ou should displa! G Kou are not an authenticated user G (se init-parameters to do this $tore the user-names and passwords in the webinf 0ml and access them in the servlet b! using the getInitParameters95 method

2se" Authenti ation 2sing Coo%ies:


Login&ht*l :html; :head; :title;login html:<title :<head; :bod! bgcolor=>pin">; :center; :h4;Coo"ies /0ample:<h4; :form action=><Wee"ACoo"ies<log>; :table; :tr; :td;:b;userid6:<b;:<td;:td;:input t!pe=>te0t> name=>username>;:<td; :<tr; :tr; :tr; :td;:b;password6:<b;:<td;:td;:input t!pe=>te0t> name=>password>;:<td; :<tr; :tr; :td;:<td; :td;:input t!pe=>submit> value=>7ogin>;:input t!pe=>reset> value=>&eset>;:<td; :<tr; :<table; :<form; :<center; :<bod!; :<html; A$$2se"s&<a=a import java io @N import java0 servlet @N import java0 servlet http @N public class Add(sers e0tends 8ttp$ervlet M public void do'et98ttp$ervlet&e3uest re3uest, 8ttp$ervlet&esponse response5 throws $ervlet/0ception, IO/0ception M response setContentT!pe9>te0t<html>5N

PrintWriter out = response getWriter95N Coo"ie user4 = new Coo"ie9>)ohn>,>)ohn4*B>5N Coo"ie user* = new Coo"ie9>)ohnson>,>)ohnson4*B>5N Coo"ie userB = new Coo"ie9>&ahul>,>&ahul4*B>5N Coo"ie userC = new Coo"ie9>&ohit>,>&ohit4*B>5N Coo"ie userD = new Coo"ie9>&aj>,>&aj4*B4*B>5N response addCoo"ie9user45N response addCoo"ie9user*5N response addCoo"ie9userB5N response addCoo"ie9userC5N response addCoo"ie9userD5N out println9>:html;:bod! bgcolor=pin";>5N out println9>:center;:h4;Coo"ies added $uccessfull!:<h4;:center;:<bod!;:<html;>5N out close95N T T LoginAo"*&<a=a import java io @N import java0 servlet @N import java0 servlet http @N public class 7ogin1orm e0tends 8ttp$ervlet M public void do'et98ttp$ervlet&e3uest re3uest, 8ttp$ervlet&esponse response5 throws $ervlet/0ception, IO/0ception M response setContentT!pe9>te0t<html>5N PrintWriter out = response getWriter95N Coo"ie csQS = re3uest getCoo"ies95N $tring user2ame = re3uest getParameter9>username>5N $tring password = re3uest getParameter9>password>5N boolean valid(ser = falseN $tring cuser2ame = nullN $tring cpassword = nullN for9Coo"ie c6cs5M cuser2ame = c get2ame95N cpassword = c get]alue95N if9cuser2ame e3uals9user2ame5 ^^ cpassword e3uals9password55 M valid(ser = trueN

brea"N T T if9valid(ser5 M out println9>:html;:bod! bgcolor=pin";>5N out println9>:h4;7ogin $uccessfull:<h4;>5N out println9>:b;Welcome > E cuser2ameE>:<b;:<bod!;:<html;>5N T else M out println9>:html;:bod! bgcolor=pin";>5N out println9>:b;>Euser2ame E >is an invalid user:<b;:<bod!;:<html;>5N T out close95N T T

web&;*l
:[0ml version=>4 +>[; :web-app; :servlet; :servlet-name;Add(sers$ervlet:<servlet-name; :servlet-class;Add(sers:<servlet-class; :<servlet; :servlet-mapping; :servlet-name;Add(sers$ervlet:<servlet-name; :url-pattern;<add:<url-pattern; :<servlet-mapping; :servlet; :servlet-name;7ogin1orm$ervlet:<servlet-name; :servlet-class;7ogin1orm:<servlet-class; :<servlet; :servlet-mapping; :servlet-name;7ogin1orm$ervlet:<servlet-name; :url-pattern;<log:<url-pattern; :<servlet-mapping; :<web-app;

Out!ut , "eens
1/ 24L : htt!:BBlo alhost:@?@:BWee%Coo%ieBa$$

./ 24L : htt!:BBlo alhost:@?@:BWee%Coo%ieBlogin&ht*l

1/ 24L: htt!:BBlo alhost:@?@:BWee%Coo%ieBlogCuse"na*eDJohnE!asswo"$DJohn1.1

2se" Authenti ation 2sing InitialiFation (a"a*ete"s:


Login&ht*l :html; :head; :title;login html:<title :<head; :bod! bgcolor=>pin">; :center; :h4;Coo"ies /0ample:<h4; :form action=><Wee"AInit<log>; :table; :tr; :td;:b;userid6:<b;:<td;:td;:input t!pe=>te0t> name=>username>;:<td; :<tr; :tr; :tr; :td;:b;password6:<b;:<td;:td;:input t!pe=>te0t> name=>password>;:<td;

:<tr; :tr; :td;:<td; :td;:input t!pe=>submit> value=>7ogin>;:input t!pe=>reset> value=>&eset>;:<td; :<tr; :<table; :<form; :<center; :<bod!; :<html;

LoginAo"*&<a=a import java io @N import java util @N import java0 servlet @N import java0 servlet http @N public class 7ogin1orm e0tends 8ttp$ervlet M public void do'et98ttp$ervlet&e3uest re3uest, 8ttp$ervlet&esponse response5 throws $ervlet/0ception, IO/0ception M response setContentT!pe9>te0t<html>5N PrintWriter out = response getWriter95N /numeration en = getInitParameter2ames95N $tring user2ame = re3uest getParameter9>username>5N $tring password = re3uest getParameter9>password>5N $tring init2ame = nullN $tring initPass = nullN boolean valid(ser=falseN while 9en has-ore/lements955 M init2ame = 9$tring5en ne0t/lement95N initPass = getInitParameter9init2ame5N if9init2ame e3uals9user2ame5 ^^ initPass e3uals9password55 M valid(ser = trueN brea"N T T if9valid(ser5 M out println9>:html;:bod! bgcolor=pin";>5N out println9>:h4;7ogin $uccessfull:<h4;>5N out println9>:b;Welcome > E user2ameE>:<b;:<bod!;:<html;>5N T else M out println9>:html;:bod! bgcolor=pin";>5N

out println9>:b;>Euser2ame E >is an invalid user:<b;:<bod!;:<html;>5N T out close95N T T

web&ht*l
:[0ml version=>4 +>[; :web-app; :servlet; :servlet-name;7ogin1orm$ervlet:<servlet-name; :servlet-class;7ogin1orm:<servlet-class; :init-param; :param-name;)ohn:<param-name; :param-value;)ohn4*B:<param-value; :<init-param; :init-param; :param-name;)ohnson:<param-name; :param-value;)ohnson4*B:<param-value; :<init-param; :init-param; :param-name;&ahul:<param-name; :param-value;&ahul4*B:<param-value; :<init-param; :init-param; :param-name;&ohit:<param-name; :param-value;&ohit4*B:<param-value; :<init-param; :init-param; :param-name;&aj:<param-name; :param-value;&aj4*B:<param-value; :<init-param; :<servlet; :servlet-mapping; :servlet-name;7ogin1orm$ervlet:<servlet-name; :url-pattern;<log:<url-pattern; :<servlet-mapping; :<web-app;

Out(ut:
(&7 6 htt!:BBlo alhost:@?@:BWee%@InitBLogin&ht*l

(&7 6 htt!:BBlo alhost:@?@:BWee%@InitBlogCuse"na*eD4ohitE!asswo"$D4ohit1.1

Wee%8G:
Install a $atabase 9M7s#l o" O"a le/& Create a table which should contain at least the following fields6 name, password, email-id, phone number 9these should hold the data from the registration form5 Practice _).BC_ connectivit! Write a java program<servlet<)$P to connect to that database and e0tract data from the tables and displa! them /0periment with various $`7 3ueries Insert the details of the users who register with the web site, whenever a new user clic"s the submit button in the registration page 9wee"*5

a/ Installation of O"a le 1? HE
,te! 1: Double li % on the ba %u! file to sta"t the installation !"o ess&
Installer will starts and shows some progress status

,te! .: On wel o*e win$ow li % on 0e;t ontine&

,te! 1: A e!t the li ense ag"ee*ent an$ li % on 0e;t to ontinue&

,te! 3: Choose $estination fol$e" to install the o"a le an$ li % 0e;t to ontinue&

,te! :: ("o=i$e the !asswo"$ as I*anage"J an$ li % 0e;t to ontinue&


91or login username is as!stem\ b! default and the password is same as !ou provide here5

,te! 5: Then installe" will show the su**a"7 of the installation& Cli % Install to ontinue with installation&

,te! >: 'e"e again the installe" shows the !"og"ess status&

,te! @: Ainall7 installe" will show the o*!letion *essage& Cli % Ainish to o*!lete the installation&

C"eation of D,0 9I*!o"tant/&


,te! 1: )o to ont"ol !anel swit h to Classi View&

,te! .: The"e sele t A$*inist"ati=e tools&

,te! 1: Then sele t Data ,ou" es 9ODBC/&

,te! 3: In ODBC Data ,ou" e A$*inist"ati=e Win$owK li % on A$$ to a$$ a new D,0 9Data ,ou" e 0a*e/&

,te! :: In C"eate 0ew Data ,ou" e win$ow sele t +Mi "osoft ODBC fo" O"a le- an$ then li % on finish to ontinue&

,te! 5: In Mi "osoft ODBC fo" O"a le ,etu! win$ow !"o=i$e the following $etails& .ata $ource 2ame6 *7$sn 9an! user defined name5 .escription6 (sername6 s ott $erver6 Clic" on o" to continue

,te! >: 1inall! !our .$2 will be listed along with alread! e0isted once Clic" on o" to complete the process now this .$2 can be used in the programs when ever !ou want connectivit! with the oracle database

Testing the onne ti=it7& A ,a*!le ("og"a* to establish onne tion with $atabase&

Out!ut:

b/ JDBC 2se" authenti ation !"og"a*&


'o*e&ht*l :html; :head;:title;8ome Page:<title; :<head; :bod! bgcolor=>pin">; :center; :h4;W/7CO-/ TO O27I2/ BOOZ $TO&/:<h4; :hD;Clic" 8ere for :a href=>7ogin html>;7O'I2 :<a;:<hD; :hD;Clic" 8ere for :a href=>&egister html>;&/'I$T/& :<a;:<hD; :<center; :<bod!; :<html;

Login&ht*l :html; :head; :title;login html:<title :<head; :bod! bgcolor=>pin">; :center; :h4;7O'I2 PA'/:<h4; :form method=>post> action=><Wee"V(serAuthen<log>; :table; :tr; :td;:b;userid6:<b;:<td;:td;:input t!pe=>te0t> name=>uname>;:<td; :<tr; :tr; :td;:b;password6:<b;:<td;:td;:input t!pe=>password> name=>pwd>;:<td; :<tr; :tr; :td;:<td; :td;:input t!pe=>submit> value=>7ogin>;:input t!pe=>reset> value=>&eset>;:<td; :<tr; :<table; :<form; :hD;.on_t 8ave a 7ogin I. Clic" here to :a href=>&egister html>;&/'I$T/& :<a;:<hD; :hD;Clic" here to go :a href=>8ome html>;8O-/ :<a;:<hD; :<center; :<bod!; :<html;

4egiste"&ht*l :html; :head; :title;&egistration page:<title; :<head; :bod! bgcolor=>pin">; :center; :h4;&/'I$T&ATIO2 PA'/:<h4; :form method=>post> action=><Wee"V(serAuthen<reg>; :table border=>B>; :tr;

:td;2ame6:<td; :td;:input t!pe=>te0t> name=>uname>;:<td; :<tr; :tr; :td;Password6:<td; :td;:input t!pe=>password> name=>pwd>;:<td; :<tr; :tr; :td;$e06:<td; :td;:input t!pe=>radio> name=>se0> value=>-ale>;-ale :input t!pe=>radio> name=>se0> value=>1emale>;1emale:<td; :<tr; :tr; :td;/mail I.6:<td; :td;:input t!pe=>te0t> name=>email>;:<td; :<tr; :tr; :td;Phone no6:<td; :td;:input t!pe=>te0t> name=>phno>;:<td; :<tr; :tr; :td;Address6:<td; :td; :te0tarea rows=>C> cols=>A> name=>addr>;:<te0tarea;:<td; :<tr; :tr; :td;:<td;:td;:input t!pe=>submit> value=>$ign In>; :input t!pe=>reset> value=>&eset>;:<td; :<tr; :<table; :<form; :hD;Alread! have a 7ogin I. Clic" here to :a href=>7ogin html>;7O'I2 :<a;:<hD; :hD;Clic" here to go :a href=>8ome html>;8O-/ :<a;:<hD; :<center; :<bod!; :<html; Login,e"=let&<a=a import java io @N import java s3l @N import java0 servlet @N import java0 servlet http @N

public class 7ogin$ervlet e0tends 8ttp$ervletM public void doPost98ttp$ervlet&e3uest hre3, 8ttp$ervlet&esponse hres5 throws $ervlet/0ception, IO/0ception M hres setContentT!pe9>te0t<html>5N PrintWriter out=hres getWriter95N tr! M Class for2ame9>sun jdbc odbc )dbcOdbc.river>5N Connection con=.river-anager getConnection9>jdbc6odbc6m!dsn>,>scott>,>tiger>5N $tring funame=hre3 getParameter9>uname>5N $tring fpwd=hre3 getParameter9>pwd>5N $tatement stmt=con create$tatement95N $tring s3l=>select @ from customer where uname=_>EfunameE>_ and pass=_>EfpwdE>_>N &esult$et rs=stmt e0ecute`uer!9s3l5N if9rs ne0t955 out println9>:h*;Welcome >EfunameE>:<h*;>5N else out println9>:h*;>EfunameE> 2ot Authori%ed:<h*;>5N con close95N out close95N T catch9/0ception e5 M $!stem out println9e5N T T T 4egiste",e"=let&<a=a import java io @N import java s3l @N import java0 servlet @N import java0 servlet http @N public class &egister$ervlet e0tends 8ttp$ervlet M public void doPost98ttp$ervlet&e3uest hre3, 8ttp$ervlet&esponse hres5 throws $ervlet/0ception, IO/0ception M hres setContentT!pe9>te0t<html>5N PrintWriter out=hres getWriter95N tr!

M Class for2ame9>sun jdbc odbc )dbcOdbc.river>5N Connection con=.river-anager getConnection9>jdbc6odbc6m!dsn>,>scott>,>tiger>5N if9conL=null5 out println9>Connection read! >5N else out println9>Connection not read! >5N $tring funame=hre3 getParameter9>uname>5N $tring fpwd=hre3 getParameter9>pwd>5N $tring fse0=hre3 getParameter9>se0>5N $tring femail=hre3 getParameter9>email>5N $tring fphno=hre3 getParameter9>phno>5N $tring faddr=hre3 getParameter9>addr>5N Prepared$tatement ps=con prepare$tatement9>insert into customer9uname,pass,se0,email,phno,addr5 values9[,[,[,[,[,[5>5N ps set$tring94,funame5N ps set$tring9*,fpwd5N ps set$tring9B,fse05N ps set$tring9C,femail5N ps set$tring9D,fphno5N ps set$tring9H,faddr5N int i=ps e0ecute(pdate95N if9i==45 out println9>:h*;&egistration $uccessfull :<h*;>5N else out println9>&egistration 1ailed >5N con close95N out close95N T catch9/0ception e5 M $!stem out println9e5N T

T T

web&;*l :[0ml version=>4 +b[; :web-app; :servlet; :servlet-name;7ogin$ervlet:<servlet-name; :servlet-class;7ogin$ervlet:<servlet-class; :<servlet; :servlet; :servlet-name;&egister$ervlet:<servlet-name; :servlet-class;&egister$ervlet:<servlet-class; :<servlet; :servlet-mapping; :servlet-name;7ogin$ervlet:<servlet-name; :url-pattern;<log:<url-pattern; :<servlet-mapping; :servlet-mapping; :servlet-name;&egister$ervlet:<servlet-name; :url-pattern;<reg:<url-pattern; :<servlet-mapping; :<web-app; Out!ut:

Wee%81?:
Write a )$P which does the following job6 Insert the details of the B or C users who register with the web site 9wee"V5 b! using registration form Authenticate the user when he submits the login form using the user name and password from the database 9similar to wee"A instead of coo"ies5

'o*e&ht*l :html; :head;:title;8ome Page:<title; :<head; :bod! bgcolor=>pin">; :center; :h4;W/7CO-/ TO O27I2/ BOOZ $TO&/:<h4; :hD;Clic" 8ere for :a href=>7ogin html>;7O'I2 :<a;:<hD; :hD;Clic" 8ere for :a href=>&egister html>;&/'I$T/& :<a;:<hD; :<center; :<bod!; :<html; Login&ht*l :html; :head; :title;login html:<title :<head; :bod! bgcolor=>pin">; :center; :h4;7O'I2 PA'/:<h4; :form method=>post> action=><Wee"4+(serAuthen<log>; :table; :tr; :td;:b;userid6:<b;:<td;:td;:input t!pe=>te0t> name=>uname>;:<td; :<tr; :tr; :td;:b;password6:<b;:<td;:td;:input t!pe=>password> name=>pwd>;:<td; :<tr; :tr; :td;:<td; :td;:input t!pe=>submit> value=>7ogin>;:input t!pe=>reset> value=>&eset>;:<td; :<tr; :<table; :<form;

:hD;.on_t 8ave a 7ogin I. Clic" here to :a href=>&egister html>;&/'I$T/& :<a;:<hD; :hD;Clic" here to go :a href=>8ome html>;8O-/ :<a;:<hD; :<center; :<bod!; :<html; 4egiste"&ht*l :html; :head; :title;&egistration page:<title; :<head; :bod! bgcolor=>pin">; :center; :h4;&/'I$T&ATIO2 PA'/:<h4; :form method=>post> action=><Wee"4+(serAuthen<reg>; :table border=>B>; :tr; :td;2ame6:<td; :td;:input t!pe=>te0t> name=>uname>;:<td; :<tr; :tr; :td;Password6:<td; :td;:input t!pe=>password> name=>pwd>;:<td; :<tr; :tr; :td;$e06:<td; :td;:input t!pe=>radio> name=>se0> value=>-ale>;-ale :input t!pe=>radio> name=>se0> value=>1emale>;1emale:<td; :<tr; :tr; :td;/mail I.6:<td; :td;:input t!pe=>te0t> name=>email>;:<td; :<tr; :tr; :td;Phone no6:<td; :td;:input t!pe=>te0t> name=>phno>;:<td; :<tr; :tr; :td;Address6:<td; :td; :te0tarea rows=>C> cols=>A> name=>addr>;:<te0tarea;:<td; :<tr; :tr;

:td;:<td;:td;:input t!pe=>submit> value=>$ign In>; :input t!pe=>reset> value=>&eset>;:<td; :<tr; :<table; :<form; :hD;Alread! have a 7ogin I. Clic" here to :a href=>7ogin html>;7O'I2 :<a;:<hD; :hD;Clic" here to go :a href=>8ome html>;8O-/ :<a;:<hD; :<center; :<bod!; :<html; Login&<s! :?J page import=>java s3l @> ?; :?J page import=>java io @> ?; :?L $tring funame,fpwd,3uer!N Connection conN $tatement stN &esult$et rsN ?; :? funame=re3uest getParameter9>uname>5N fpwd=re3uest getParameter9>pwd>5N tr! M Class for2ame9>sun jdbc odbc )dbcOdbc.river>5N con=.river-anager getConnection9>)dbc6Odbc6m!dsn>,>scott>,>tiger>5N st=con create$tatement95N 3uer!=>select @ from customer where uname=_>EfunameE>_ and pass=_>EfpwdE>_>N rs=st e0ecute`uer!93uer!5N if9rs ne0t955 M ?; :h4;WelCome :?=funame?;:<h4; :? T else M ?; :h4;:?=funame?; Invalid (ser:<h4; :?

T T catch9/0ception e5 M out println9e5N T?; 4egiste"&<s! :?J page import=>java s3l @> ?; :?J page import=>java io @> ?; :?L $tring funame,fpwd,fse0,femail,fphno,faddr,3uer!N Connection conN Prepared$tatement pstN &esult$et rsN ?; :? tr! M Class for2ame9>sun jdbc odbc )dbcOdbc.river>5N Connection con=.river-anager getConnection9>jdbc6odbc6m!dsn>,>scott>,>tiger>5N if9conL=null5 out println9>Connection read! >5N else out println9>Connection not read! >5N funame=re3uest getParameter9>uname>5N fpwd=re3uest getParameter9>pwd>5N fse0=re3uest getParameter9>se0>5N femail=re3uest getParameter9>email>5N fphno=re3uest getParameter9>phno>5N faddr=re3uest getParameter9>addr>5N pst=con prepare$tatement9>insert into customer9uname,pass,se0,email,phno,addr5values9[,[,[,[,[,[5>5N pst set$tring94,funame5N pst set$tring9*,fpwd5N pst set$tring9B,fse05N pst set$tring9C,femail5N pst set$tring9D,fphno5N pst set$tring9H,faddr5N int i=pst e0ecute(pdate95N if9i==45 M ?;

:h*;&egistration $uccessfull :? T else M ?; :h*;&egistration 1ailed :?

:<h*;

:<h*;

T con close95N out close95N T catch9/0ception e5 M $!stem out println9e5N T ?;

Out(ut:

Wee%811: Create tables in the database which contain the details of items 9boo"s in our case li"e Boo" name , Price, `uantit!, Amount 55 of each categor! -odif! !our catalogue page 9wee" *5 in such a wa! that !ou should connect to the database and e0tract data from the tables and displa! them in the catalogue page using ).BC

Database: 45 Create the following table $`7; create table boo"info9title varchar*9*+5,author varchar*9B+5, edition varch ar*9D5,price varchar*9I5,3uant varchar*9D5,amount varchar*9I55N *5 Insert the following records $`7; insert into boo"info values9_)ava_,_Complete reference_,_Drd_,_4*+ ++_,_*I_ ,_4+++_5N 4 row created $`7; insert into boo"info values9_)ava $erver Pages_,_P$W_,_Brd_,_4IC ++_,_*V_,_ V+++_5N 4 row created $`7; commitN Commit complete atalogue&<s! :?J page import=>java s3l @> ?; :?J page import=>java io @> ?; :?L $tring btitle,bauthor,bedition,bprice,b3uantiti!,bamount,3uer!N Connection conN $tatement stN &esult$et rsN ?; :? tr! M Class for2ame9>sun jdbc odbc )dbcOdbc.river>5N con=.river-anager getConnection9>)dbc6Odbc6m!dsn>,>scott>,>tiger>5N st=con create$tatement95N 3uer!=>select @ from boo"info>N rs=st e0ecute`uer!93uer!5N if9rs ne0t955 M ?; :center; :h4;Boo"s Information:<h4; :table border=>4>;

:thead; :tr bgcolor=>gra!>; :th;Title:<th; :th;Author:<th; :th;/dition:<th; :th;Price:<th; :th;`uantit!:<th; :th;Amount:<th; :th;Add to cart:<th; :<tr; :<thead; :tbod!; :tr bgcolor=>!ellow>; :td;:?=rs get$tring945?;:<td; :td;:?=rs get$tring9*5?;:<td; :td;:?=rs get$tring9B5?;:<td; :td;:?=rs get$tring9C5?;:<td; :td;:?=rs get$tring9D5?;:<td; :td;:?=rs get$tring9H5?;:<td; :td;:input t!pe=>submit> value=>Add to Cart> <;:<td; :<tr; :? while9rs ne0t955 M ?; :tr bgcolor=>!ellow>; :td;:?=rs get$tring945?;:<td; :td;:?=rs get$tring9*5?;:<td; :td;:?=rs get$tring9B5?;:<td; :td;:?=rs get$tring9C5?;:<td; :td;:?=rs get$tring9D5?;:<td; :td;:?=rs get$tring9H5?;:<td; :td;:input t!pe=>submit> value=>Add to Cart> <;:<td; :<tr; :? T ?; :<tbod!; :<table; :<center; :? T else

M ?; :h4; 2o data 1ound:<h4; :? T T catch9/0ception e5 M $!stem out println9e5N T?;

O2T(2T:

Wee%81.: 'TT( is a stateless protocol $ession is re3uired to maintain the state The user ma! add some items to cart from the catalog page 8e can chec" the cart page for the selected items 8e ma! visit the catalogue again and select some more items 8ere our interest is the selected items should be added to the old cart rather than a new cart -ultiple users can do the same thing at a time9i e , from different s!stems in the 7A2 using the ipaddress instead of local host5 This can be achieved through the use of sessions /ver! user will have his own session which will be created after his successful login to the website When the user logs out his session should get invalidated 9b! using the method session invalidate95 5 -odif! !our catalogue and cart )$P pages to achieve the above mentioned functionalit! using sessions

Vous aimerez peut-être aussi