0% found this document useful (0 votes)
121 views

Web Programming Sample Examples

The document outlines creating static HTML pages for an online bookstore website with the following pages: 1. Home page 2. Registration and user login 3. User profile page 4. Books catalog 5. Shopping cart 6. Payment by credit card 7. Order confirmation It then provides the code for each page to display the basic layout and functionality required. Validation of the registration, user profile and payment pages is added using JavaScript. Finally, it describes creating an XML document on the server to store user information and retrieving a user's details based on their login credentials.

Uploaded by

rafath5
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
121 views

Web Programming Sample Examples

The document outlines creating static HTML pages for an online bookstore website with the following pages: 1. Home page 2. Registration and user login 3. User profile page 4. Books catalog 5. Shopping cart 6. Payment by credit card 7. Order confirmation It then provides the code for each page to display the basic layout and functionality required. Validation of the registration, user profile and payment pages is added using JavaScript. Finally, it describes creating an XML document on the server to store user information and retrieving a user's details based on their login credentials.

Uploaded by

rafath5
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 94

1.

AIM:
Develop static pages (using only HTML) of an online Book store. T e pages s oul! rese"#le: $$$.a"a%on.co". T e $e#site s oul! consist t e follo$ing pages.
Ho"e page &egistration an! user Login 'ser profile page Books catalog ( opping cart )ay"ent #y cre!it car! *r!er +onfor"ation

)&*+,D'&,: Ho"e page


Main. t"l:
<html> <head> <title> Amazon</title> </head> <body bgcolor="cyan"> <center> <strong><h1>Welcome to AMAZON</h1></strong> <form method=" ost" action="login!html" target="blan# > <h$>%or &oo#s 'nformation </h$><in (t ty e="s(bmit" )al(e="clic# here"> </form> </center> </body> </html>

&egistration an! user Login


Login. t"l:
<html> <head> <title> login age</title> </head> <body bgcolor="cyan"> <center> <strong><h1> AMAZON </h1></strong></center> <right> <table align="center" border="*"> <tr> <form method=" ost" action="catalog!html" > <td><h$>+ser name,</td> <td><in (t ty e="te-t" ></td> <td></td> </tr> <tr> <td><h$>.ass/ord,</td> <td><in (t ty e=" ass/ord"></td> <td></td> </tr> <tr> <td> </td> <td><in (t ty e="s(bmit" )al(e="0(bmit" )al(e="1eset"></td> </form> </td> <td> </td> </tr> </table>

><in (t

ty e="reset"

<table align="center" border="*"> <tr><td>%or registration 2lic# 3ere</td></tr> <tr> <td> <form method=" ost" action="(ser ro!html"> 4nbs 54nbs 54nbs 54nbs 54nbs 54nbs 54nbs 54nbs 54nbs 54nbs 54nbs 54nbs 54nbs 5 <in (t ty e="s(bmit" )al(e="1egister" > </form> </td></tr> </table></body></html>

'ser profile page


'serpro. t"l:
<html> <head> <title> login age</title> </head> <body bgcolor="cyan"> <center><strong><h1> AMAZON </h1></strong></center> <center><strong><h6> +071 .1O%'87</h6></strong></center> <form method=" ost" action="catalog!html" > <right> <table align="27N971"> <tr> <td>+sername,</td> <td><in (t ty e="te-t" name="name1"></td> </tr> <tr> <td>.ass/ord,</td> <td><in (t ty e=" ass/ord" name=" ass1"></td> </tr> <tr> <td>2onfirm .ass/ord,</td> <td><in (t ty e=" ass/ord" name=" ass6"></td> </tr> <tr> <td>:ender, </td><td> Male,<in (t ty e="radio" name="se-" id="male">%emale, <in (t ty e="radio" name="se-" id="female" ></td> </tr> <tr> <td>Address,</td> <td><te-tarea name="address" ro/s=; cols=1<> </te-tarea> </td> <tr><td></td> <td> <in (t ty e="s(bmit" )al(e="s(bmit" > <in (t ty e="reset" )al(e="reset"></td> </tr> </form></body></html>

Books catalog
+atalog. t"l:
<html> <head> <title> boo#s catalog</title> </head> <body bgcolor="cyan"> <center><h1>AMAZON</h1></center> <form method=" ost" action="sho ing!html"> <left> <table> <tr> <td><b><h=>2om (ter rogramming boo#s</td> <td></td></tr> <tr> <td></td> <td><h$>24>s</td> </tr> <tr> <td></td> <td><h$>Ads</td> </tr> <tr> <td></td> <td><h$>?A@A </td></tr> <tr> <td><b><h=>>atabase boo#s</td> <td></td> </tr> <tr> <td></td> <td><h$>Oracle</td> </tr> <tr> <td></td> <td><h$>Ms 0A8 0er)er </td></tr> <tr> <td></td> <td><h$>My0Bl </td> </tr> </table> </h$>

<center> <b>9o b(y one of these boo#s <br> </b><in (t ty e="s(bmit" )al(e="clic# here"> </center> </form> </body> </html>

( opping cart
( opping. t"l:
<html> <head><title>sho ing cart</title> </head> <body bgcolor="cyan"> <center><h1> 0ho ing 2art</h1></center> <br><br><br><br><br> <table align="center"> <tr> <td>9e-t &oo#s</td> <td> <select > <o t gro( label="select the boo#"> <o tion )al(e="24>0">24>0 <o tion )al(e="A>0">A>0 <o tion )al(e="?a)a">?A@A <o tion )al(e="Oracle">O1A287 <o tion )al(e="Ms 0A8 0er)er">Ms 0A8 0er)er <o tion )al(e="My0Bl">My0Bl </o tgro( > </select> </td></tr> <tr> <td> A(antity</td> <td> <in (t ty e="te-t" id="B"> </td></tr> <tr> <td></td> <td> <form method= ost action=" ayment!html"> ;

<in (t ty e="s(bmit" )al(e=o# /> </form> </td></tr> </table> <center> < re>2ost of one boo# = ;**!** <br> shi ing is = 1**!**</ re> </center> </body> </html>

)ay"ent #y cre!it car!


)ay"ent. t"l:
<html> <head><title> ayment</title></head> <body bgcolor="cyan"> <center><h1>.ayment &y 2redit 2ard</h1></center> <form method= ost action="ordrconform!html"> <br><br><br><br><br> <table align="center"> <tr> <td>9otal Amo(nt,</td> <td><in (t ty e="te-t" name="amo(nt"> </td> </tr> <tr> <td>2redit 2ard N(mber,</td> <td><in (t ty e="te-t" name="ccno"></td> </tr> <tr> <td>2)) 2ode,</td> <td><in (t ty e="te-t" name="ccno"> </td> </tr> <tr> <td></td> <td><in (t ty e="s(bmit" )al(e="0(bmit"> </td> </tr> </table> </form></body> </html>

*r!er +onfor"ation
*r!rconfor". t"l:
<html> <head><title>order conformation</title></head> <body bgcolor="cyan"> <center> <h1><b>AMAZON</h1> Do(r order 's 2onformed <h6><b>93ANE DO+</h6> </center> </body></html>

&esult: Ho"e page:

&egistration an! user Login:

<

'ser profile page:

1*

Books catalog:

11

( opping cart:

16

)ay"ent #y cre!it car!:

1=

*r!er +onfor"ation:

1$

-. AIM:
.ali!ate t e &egistration/ user login/ user profile an! pay"ent #y cre!it car! pages using 0ava(cript. )&*+,D'&,:

&egistration an! user Login


Login. t"l:
<html> <body bgcolor=" in#"><br><br><br> <scri t ty e="te-t/Ha)ascri t"> f(nction )alidateIJ K )ar flag=15 ifIdoc(ment!myform!id!)al(e==""LL doc(ment!myform! /d!)al(e==""J K flag=*5 M ifIflag==1J K alertI"@A8'> 'N.+9"J5 M else K alertI"'N@A8'> 'N.+9"J5 doc(ment!myform!foc(sIJ5 M M </scri t> <form name="myform"> <di) align="center"> <table> <tr><td> 8O:'N '>,</td><td><in (t ty e="te-t" name="id"></td></tr> <tr><td>.A00WO1>,</td><td><in (t ty e=" ass/ord" name=" /d"></td></tr> </di)> <di) align="center"> <tr><td></td><td> <in (t ty e="s(bmit" )al(e="s(bmit" on2lic#=")alidateIJ">4nbs 54nbs 54nbs 54nbs 5 <in (t ty e="reset" )al(e="1eset" ></td</tr></table></form></body></html> 1;

'ser profile page


)rofile. t"l:
<html> <body bgcolor=" in#"><br><br> <scri t ty e="te-t/Ha)ascri t"> f(nction )alidateIJ K )ar flag=15 ifIdoc(ment!myform!name!)al(e==""LL doc(ment!myform!addr!)al(e==""LL doc(ment!myform! hno!)al(e==""LL doc(ment!myform!id!)al(e==""LL doc(ment!myform! /d!)al(e==""J K flag=*5 M )ar str=doc(ment!myform! hno!)al(e5 )ar -5 forI)ar i=*5i<str!length5iNNJ K -=str!s(bstrIiO1J ifIPI-<=<JJ K flag=*5 brea#5 M M ifIflag==1J K alertI"@A8'> 'N.+9"J5 M else K alertI"'N@A8'> 'N.+9"J5 doc(ment!myform!foc(sIJ5 M M </scri t> <form name="myform"> <di) align="center"> <table> <tr> <td> NAM7,</td><td><in (t ty e="te-t" name="name"></td></tr> <tr><td>A>>1700,</td><td><in (t ty e="ty e" name="addr"></td></tr>

1C

<tr><td>2ON9A29 N+M&71,</td><td><in (t ty e="te-t" name=" hno"></td></tr> <tr><td>8O:'N'>,</td><td><in (t ty e="te-t" name="id"></td></tr> <tr><td>.A00WO1>,</td><td><in (t ty e=" ass/ord" name=" /d"></td></tr> </di)> <di) align="center"> <tr><td></td><td> <in (t ty e="s(bmit" )al(e="s(bmit" on2lic#=")alidateIJ">4nbs 54nbs 54nbs 5 <in (t ty e="reset" )al(e="1eset"></td></tr></table> </form></body></html>

1F

)ay"ent #y cre!it car!


)ay"ent. t"l:
<html> <head> <scri t ty e="te-t/Ha)ascri t"> f(nction )alidateIJ K )ar flag=15 ifIdoc(ment!myform!id!)al(e==""LLdoc(ment!myform! /d!)al(e==""LL doc(ment!myform!amo(nt!)al(e==""LLdoc(ment!myform!n(m!)al(e==""J K flag=*5 M )ar str=doc(ment!myform!amo(nt!)al(e5 )ar -5 forI)ar i=*5i<str!length5iNNJ K -=str!s(bstrIiO1J5 ifIPI-<=<JJ K flag=*5 brea#5 M M str=doc(ment!myform!n(m!)al(e5 forI)ar i=*5i<str!length5iNNJ K -=str!s(bstrIiO1J5 ifIPI-<=<JJ K flag=*5 brea#5 M M ifIflag==1J K alertI"@A8'> 'N.+9"J5 M else K alertI"'N@A8'> 'N.+9"J5 M M </scri t> 1G

</head> <body bgcolor=" in#"> <form name="myform" ons(bmit="ret(rn )alidateIJ"> <di) align="center"> <table><tr><td>8O:'N '> ,</td><td><in (t ty e="te-t" name="id"></td></tr> <tr><td>.A00WO1>,</td><td><in (t ty e=" ass/ord" name=" /d"></td></tr> <tr><td>AMO+N9,</td><td><in (t ty e="te-t" name="amo(nt"></td></tr> <tr><td>217>'92A1>N+M&71,</td><td><in (t ty e="te-t" name="n(m"></td></tr> </di)> <di) align="center"> <tr><td></td><td> <in (t ty e="s(bmit" )al(e="0(bmit"> <in (t ty e="reset" )al(e="1eset" > </td></tr></table> </form> </body> </html>

1<

&esult: &egistration an! user Login

6*

'ser profile page

61

)ay"ent #y cre!it car!

66

1. AIM:
2reate and 0a)e an QM8 doc(ment at the ser)erO /hich contains 1* (sers information! Write a rogramO /hich ta#es (ser '> as in (t and ret(rns the (ser details by ta#ing the (ser information from QM8 >oc(ment!

)roce!ure:

Login )age:

Login. t"l:
<html> <head> <scri t ty e="te-t/Ha)ascri t"> f(nction serIJ K ) -mldoc=ne/ Acti)eQObHectI"Microsoft!QM8>OM"J5 -mldoc!loadI"(sers!-ml"J5 )ar id=f1!id!)al(e5 )ar ass=f1! ass!)al(e5 )ar -=-mldoc!get7lements&y9agNameI"(serid"J5 )ar y=-mldoc!get7lements&y9agNameI" ass/ord"J5 forIi=*5i<-!length5iNNJ K ifI-RiS!childNodesR*S!node@al(e==idJ K ifIyRiS!childNodesR*S!node@al(e== assJ K alertI"s(ccessf(ll logged"J5 )ar ob=/indo/!o enI"(serinfo!html"O""blan#"J5 ob!doc(ment!f1!(id!)al(e=-RiS!childNodesR*S!node@al(e5 -mldoc!loadI"(serinfo!-ml"J5 )ar -*=-mldoc!get7lements&y9agNameI"(serid"J5 )ar -1=-mldoc!get7lements&y9agNameI"(sername"J5 )ar -6=-mldoc!get7lements&y9agNameI"B(alification"J5 )ar -==-mldoc!get7lements&y9agNameI"Hob"J5 )ar -$=-mldoc!get7lements&y9agNameI"com anyname"J5 )ar -;=-mldoc!get7lements&y9agNameI"dob"J5 )ar -C=-mldoc!get7lements&y9agNameI"street"J5 )ar -F=-mldoc!get7lements&y9agNameI"city"J5 forI)ar H=*5H<-*!length5HNNJ K

6=

ifI-*RHS!childNodesR*S!node@al(e==idJ K ob!doc(ment!f1!(name!)al(e=-1RHS!childNodesR*S!node@al(e5 ob!doc(ment!f1!B(al!)al(e=-6RHS!childNodesR*S!node@al(e5 ob!doc(ment!f1!Hn!)al(e=-=RHS!childNodesR*S!node@al(e5 ob!doc(ment!f1!cn!)al(e=-$RHS!childNodesR*S!node@al(e5 ob!doc(ment!f1!dob!)al(e=-;RHS!childNodesR*S!node@al(e5 ob!doc(ment!f1!address!)al(e=-CRHS!childNodesR*S!nod e@al(eN"O"N-FRHS!childNodesR*S!node@al(e5 M M M else alertI"incorrect ass/ord"J5 ret(rn5 M M alertI"incorrect (serid"J 5 M </scri t> </head> <body> <form name="f1"> <center> <h1>8ogin %orm</h1> <br><&>+ser 'd, 4nbs 54nbs 5<in (t ty e="te-t" name="id"> <br><br>.ass/ord,</&><in (t ty e =" ass/ord" name=" ass"> <br><br> <in (t ty e="b(tton" )al(e="s(bmit" on2lic#="serIJ"> </center> </form> </body> </html>

6$

'ser infor"ation page:


'serinfo. t"l:
<html> <head> <title>+ser 'nfo</title> </head> <body> <center> <h1>+ser 'nformation</h1> <form name="f1"> < re> <&> +ser 'd, <in (t ty e="te-t" name="(id" onbl(r="f(nIJ"> +ser Name, <in (t ty e="te-t" name="(name"> A(alification, <in (t ty e="te-t" name="B(al"> ?ob, <in (t ty e="te-t" name="Hn"> 2om any, <in (t ty e="te-t" name="cn"> >ate Of &irth, <in (t ty e="te-t" name="dob"> Address, <te-tarea name="address" ro/s=; cols=1<> </te-tarea> </&> </ re> </form> </center> </body> </html>

6;

'sers 2"l pages:


'sers.2"l:
<T-ml )ersion="1!*" encoding="+9%UG"T> <(sers> <(ser> <(serid>1</(serid> < ass/ord>a</ ass/ord> </(ser> <(ser> <(serid>6</(serid> < ass/ord>b</ ass/ord> </(ser> <(ser> <(serid>=</(serid> < ass/ord>c</ ass/ord> </(ser> <(ser> <(serid>$</(serid> < ass/ord>d</ ass/ord> </(ser> <(ser> <(serid>;</(serid> < ass/ord>e</ ass/ord> </(ser> <(ser> <(serid>C</(serid> < ass/ord>f</ ass/ord> </(ser> </(sers>

6C

'serinfo.2"l:
<T-ml )ersion="1!*" encoding="+9%UG"T> <(serinfo> <(ser> <(serid>1</(serid> <(sername>abc</(sername> <B(alification>def</B(alification> <Hob>ghi</Hob> <com anyname>H#l</com anyname> <dob>may*COGG</dob> <address> <street>mno</street> <city> Br</city> </address> </(ser> <(ser> <(serid>6</(serid> <(sername>def</(sername> <B(alification>ghi</B(alification> <Hob>H#l</Hob> <com anyname>mno</com anyname> <dob>H(ne6$OGG</dob> <address> <street> Br</street> <city>st(</city> </address> </(ser> <(ser> <(serid>=</(serid> <(sername>ghi</(sername> <B(alification>H#l</B(alification> <Hob>mno</Hob> <com anyname> Br</com anyname> <dob>may*FOGC</dob> <address> <street>st(</street> <city>)/-</city> </address> </(ser> <(ser> <(serid>$</(serid> <(sername>H#l</(sername> <B(alification>mno</B(alification> <Hob> Br</Hob> <com anyname>st(</com anyname> <dob>se COGG</dob>

6F

<address> <street>)/-</street> <city>yz</city> </address> </(ser> <(ser> <(serid>;</(serid> <(sername>mno</(sername> <B(alification> Br</B(alification> <Hob>st(</Hob> <com anyname>)/-</com anyname> <dob>a(g6=OGF</dob> <address> <street>yz</street> <city>abc</city> </address> </(ser> <(ser> <(serid>C</(serid> <(sername> Br</(sername> <B(alification>st(</B(alification> <Hob>)/-</Hob> <com anyname>yz</com anyname> <dob>oct66OGG</dob> <address> <street>abc</street> <city>def</city> </address> </(ser> </(serinfo>

6G

*utput:

Login page:

6<

'ser infor"ation page:

=*

3. AIM:
Install T*M+AT $e# server. +onvert t e static $e#pages of assign"ents - into !yna"ic $e#pages using servlets an! cookies. Hint: 'sers infor"ation (user i!/ pass$or!/ cre!it car! nu"#er) $oul! #e store! in $e#.2"l. ,ac user s oul! ave a separate ( opping +art.

)&*+,D'&,:
%irst install the tomcat into the system! 9hen ma#e a s(bdirectlyIeg!O trJ in the VtomcatV/eba s! +nder tr create W7&U'N% directory and also lace the html files in this tr directory only! Ne-t (nder W7&U'N% create t/o s(bclasses libOclasses and /eb!-ml Ne-t lace all the class files (nder the classes and Har filesIser)letUa i!HarOclasses16!Har etcWJ (nder lib s(bdirectories! After this start tomcat by gi)ing the follo/ing command at the instll"dir>tomcat>bin 2atalina!bat r(n At the '!7I/eb bro/serJ gi)e the (rl as htt 5//localhost,G*G*//tr/htmlfile or ser)let (rl attern .ortno G*G* is assigned for the tomcat!

Ho"e page:
Main. t"l:
<html> <body> <br /><br /><br /><br /><br /> <h1 align="center"><+>ON8'N7 &OOE 09O1A:7</+></h1><br /><br /><br /> <h6 align="center">< re> <b>Welcome to online boo# storage! .ress 8O:'N if yo( are ha)ing id other/ise ress 17:'091A9'ON </b></ re></h6> <br /><br />< re> <di) align="center"><a href="login!html">8O:'N</a> <a href="reg!html"> 17:'091A9'ON</a></di)></ re> </body> </html>

=1

Login page:
Login. t"l:
<html> <body><br /><br /><br /> <form name="myform" method=" ost" action="login"> <di) align="center">< re> 8O:'N '> ,<in (t ty e="te-t" name="id" /><br /> .A00WO1> ,<in (t ty e=" ass/ord" name=" /d" /></ re><br /><br /> </di)> <br /><br /> <di) align="center"> <in (t ty e="s(bmit" )al(e="o#" onclic#=")alidateIJ" /> 4nbs 54nbs 54nbs 54nbs 54nbs 54nbs 5<in (t ty e="reset" )al(e="clear" /> </di)> </form> </body> </html>

=6

&egistration page:
&eg. t"l:
<html> <body><br /><br /> <form name="myform" method=" ost" action="reg"> <table align="center" > <tr> <td>NAM7</td> <td>,<in (t ty e="te-t" name="name" /></td> </tr> <tr> <td>A>>1700</td> <td>,<in (t ty e="te-t" name="addr" /></td> </tr> <tr> <td>2ON9A29 N+M&71</td> <td>,<in (t ty e="te-t" name=" hno" /></td> </tr> <tr> <td>8O:'N'></td> <td>,<in (t ty e="te-t" name="id" /></td> </tr> <tr> <td>.A00WO1></td> <td>,<in (t ty e=" ass/ord" name=" /d" /></td> </tr> </table> <br /><br /> <di) align="center"> <in (t ty e="s(bmit" )al(e="o#" onclic#=")alidateIJ" /> 4nbs 54nbs 54nbs 54nbs 54nbs 54nbs 5<in (t ty e="reset" )al(e="clear" /> </di)> </form> </body> </html>

==

'ser profile page:


)rofile. t"l:
<html> <body><br /><br /><br /> <form name="myform" method=" ost" action=" rofile"> <di) align="center">< re> 8O:'N '> ,<in (t ty e="te-t" name="id" /><br /> </ re><br /><br /> </di)> <br /><br /> <di) align="center"> <in (t ty e="s(bmit" )al(e="o#" onclic#=")alidateIJ" /> 4nbs 54nbs 54nbs 54nbs 54nbs 54nbs 5<in (t ty e="reset" )al(e="clear" /> </di)> </form> </body> </html>

Books catalog page:


+atalog. t"l:
<html> <body><br /><br /><br /> <form method=" ost" action="catalog"> <di) align="center">< re> &OOE 9'987 ,<in (t ty e="te-t" name="title" /><br /> </ re><br /><br /> </di)> <br /><br /> <di) align="center"> <in (t ty e="s(bmit" )al(e="o#" name="b(tton1"/>4nbs 54nbs 54nbs 54nbs 54nbs 54nbs 5 <in (t ty e="reset" )al(e="clear" name="b(tton6"/> </di)> </form> </body> </html>

=$

( opping cart/ )ay"ent #y cre!it car!/ *r!er +onfor"ation page:


*r!er. t"l:
<html> <body><br /><br /> <form method=" ost" action="order"> <di) align="center">< re> '> ,<in (t ty e="te-t" name="id" /><br /> .A00WO1> ,<in (t ty e=" ass/ord" name=" /d" /><br/> 9'987 ,<in (t ty e="te-t" name="title" /><br /> NO! O% &OOE0 ,<in (t ty e="te-t" name="no" /><br /> >A97 ,<in (t ty e="te-t" name="date" /><br /> 217>'9 2A1> N+M&71 ,<in (t ty e=" ass/ord" name="cno" /><br /></ re><br /><br /> </di)> <br /><br /> <di) align="center"> <in (t ty e="s(bmit" )al(e="o#" name="b(tton1"/> 4nbs 54nbs 54nbs 54nbs 54nbs 54nbs 5<in (t ty e="reset" )al(e="clear" name="b(tton6"/> </di)> </form> </body> </html>

=;

Login servlet:
Login.4ava:

im ort Ha)a!sBl!X5 im ort Ha)a!io!X5 im ort Ha)a-!ser)let!X5 im ort Ha)a-!ser)let!htt !X5 (blic class login e-tends 3tt 0er)let K (blic )oid ser)iceI3tt 0er)let1eB(est reBO3tt 0er)let1es onse res J thro/s 0er)let7-ce tionO'O7-ce tion K .rintWriter /=res !getWriterIJ5 /! rintlnI"<html><body>"J5 0tring id=reB!get.arameterI"id"J5 0tring /d=reB!get.arameterI" /d"J5 try K 2lass!forNameI"s(n!Hdbc!odbc!?dbcOdbc>ri)er"J5 2onnection con=>ri)erManager!get2onnectionI"Hdbc,odbc,orcl"O"scott"O"ti ger"J5 0tatement stmt=con!create0tatementIJ5 0tring sBlstmt="select idO /d from login"5 1es(lt0et rs=stmt!e-ec(teA(eryIsBlstmtJ5 int flag=*5 /hileIrs!ne-tIJJ K ifIid!eB(alsIrs!get0tringI1JJ44 /d!eB(alsIrs!get0tringI6JJJ K flag=15 M M ifIflag==*J K /! rintlnI"<br><br>0O11D 'N@A8'> '> 91D A:A'N '><br><br>"J5 /! rintlnI"<a href=V"login!htmlV"> ress 8O:'N to 1791D</a>"J5 M else K /! rintlnI"<br><br>@A8'> 8O:'N '><br><br>"J5

=C

/! rintlnI"<h=><(l>"J5 /! rintlnI"<li><a href=V" rofile!htmlV"><fontcolor=V"blac#V">+071 .1O%'87</font> </a></li><br><br>"J5 /! rintlnI"<li><a href=V"catalog!htmlV"><fontcolor=V"blac#V">&OOE0 2A9A8O:</font></a></li><br><br>"J5 /! rintlnI"<li><a href=V"order!htmlV"><fontcolor=V"blac#V">O1>71 2ON%'1MA9'ON</font> </a></li></(l><br><br>"J5 M /! rintlnI"</body></html>"J5 M catchI7-ce tion eJ K res !send7rrorI;**Oe!to0tringIJJ5 M M M

=F

&egistration servlet:
&eg.4ava:
im ort Ha)a!sBl!X5 im ort Ha)a!io!X5 im ort Ha)a-!ser)let!X5 im ort Ha)a-!ser)let!htt !X5 (blic class reg e-tends 3tt 0er)let K (blic )oid ser)iceI3tt 0er)let1eB(est reBO3tt 0er)let1es onse res J thro/s 0er)let7-ce tionO'O7-ce tion K .rintWriter /=res !getWriterIJ5 res !set2ontent9y eI"te-t/html"J5 /! rintlnI"<html><body>"J5 0tring name=reB!get.arameterI"name"J5 0tring addr=reB!get.arameterI"addr"J5 0tring hno=reB!get.arameterI" hno"J5 0tring id1=reB!get.arameterI"id"J5 0tring /d1=reB!get.arameterI" /d"J5 int no='nteger! arse'ntI hnoJ5 try K 2lass!forNameI"s(n!Hdbc!odbc!?dbcOdbc>ri)er"J5 2onnection con=>ri)erManager!get2onnectionI"Hdbc,odbc,orcl"O"scott"O"ti ger"J5 0tatement stmt=con!create0tatementIJ5 0tring sBlstmt="select idO /d from login"5 1es(lt0et rs=stmt!e-ec(teA(eryIsBlstmtJ5 int flag=*5 /hileIrs!ne-tIJJ K ifIid1!eB(alsIrs!get0tringI1JJ44 /d1!eB(alsIrs!get0tringI6JJJ K flag=15 M M ifIflag==1J K /! rintlnI"<br><br>0O11D 'N@A8'> '> A817A>D 7Q'90 91D A:A'N W'93 N7W '><br><br>"J5 =G

/! rintlnI"<a href=V"reg!htmlV"> ress 17:'0971 to 1791D</a>"J5 M else K 0tatement stmt1=con!create0tatementIJ5 stmt1!e-ec(te+ dateI"insert into login )al(esIY"NnameN"YOY"NaddrN"YO"NnoN"OY"Nid1N"YOY"N /d1 N"YJ5"J5 /! rintlnI"<br><br>DO+1 >79A'80 A17 7N9717><br><br>"J5 /! rintlnI"<a href=V"login!htmlV"> ress 8O:'N to login</a>"J5 M /! rintlnI"</body></html>"J5 M catchI7-ce tion eJ K res !send7rrorI;**Oe!to0tringIJJ5 M M M

=<

)rofile servlet:
)rofile.4ava:
im ort Ha)a!sBl!X5 im ort Ha)a!io!X5 im ort Ha)a-!ser)let!X5 im ort Ha)a-!ser)let!htt !X5 (blic class rofile e-tends 3tt 0er)let K (blic )oid ser)iceI3tt 0er)let1eB(est reBO3tt 0er)let1es onse res J thro/s 0er)let7-ce tionO'O7-ce tion K .rintWriter /=res !getWriterIJ5 /! rintlnI"<html><body>"J5 0tring id=reB!get.arameterI"id"J5 try K 2lass!forNameI"s(n!Hdbc!odbc!?dbcOdbc>ri)er"J5 2onnection con=>ri)erManager!get2onnectionI"Hdbc,odbc,orcl"O"scott"O"ti ger"J5 0tatement stmt=con!create0tatementIJ5 0tring sBlstmt="select X from login /here id="NidN""5 1es(lt0et rs=stmt!e-ec(teA(eryIsBlstmtJ5 int flag=*5 /! rintlnI"<br><br><br>"J5 /hileIrs!ne-tIJJ K /! rintlnI"<di) align=V"centerV">"J5 /! rintlnI"NAM7 ,"Nrs!get0tringI1JN"<br>"J5 /! rintlnI"A>>1700 ,"Nrs!get0tringI6JN"<br>"J5 /! rintlnI".3ON7 NO ,"Nrs!get0tringI=JN"<br>"J5 /! rintlnI"</di)>"J5 flag=15 M ifIflag==*J K /! rintlnI"<br><br>0O11D 'N@A8'> '> 91D A:A'N '><br><br>"J5 /! rintlnI"<a href=V" rofile!htmlV"> ress 3717 to 1791D</a>"J5 M /! rintlnI"</body></html>"J5 M

$*

catchI7-ce tion eJ K res !send7rrorI;**Oe!to0tringIJJ5 M M M

$1

+atalog servlet:
+atalog.4ava:
im ort Ha)a!sBl!X5 im ort Ha)a!io!X5 im ort Ha)a-!ser)let!X5 im ort Ha)a-!ser)let!htt !X5 (blic class catalog e-tends 3tt 0er)let K (blic )oid ser)iceI3tt 0er)let1eB(est reBO3tt 0er)let1es onse res J thro/s 0er)let7-ce tionO'O7-ce tion K .rintWriter /=res !getWriterIJ5 /! rintlnI"<html><body>"J5 0tring title=reB!get.arameterI"title"J5 try K 2lass!forNameI"s(n!Hdbc!odbc!?dbcOdbc>ri)er"J5 2onnection con=>ri)erManager!get2onnectionI"Hdbc,odbc,orcl"O"scott"O"ti ger"J5 0tatement stmt=con!create0tatementIJ5 0tring sBlstmt="select X from boo# /here title=VY"NtitleN"VY"5 1es(lt0et rs=stmt!e-ec(teA(eryIsBlstmtJ5 int flag=*5 /hileIrs!ne-tIJJ K /! rintlnI"<di) align=V"centerV">"J5 /! rintlnI"9'987 ,"Nrs!get0tringI1JN"<br>"J5 /! rintlnI"A+93O1 /! rintlnI"@710'ON ,"Nrs!get0tringI6JN"<br>"J5

,"Nrs!get0tringI=JN"<br>"J5 /! rintlnI".+&8'0371 ,"Nrs!get0tringI$JN"<br >"J5 /! rintlnI"2O09 ,"Nrs!get0tringI;JN"<br>"J5 /! rintlnI"</di)>"J5 flag=15 M ifIflag==*J K /! rintlnI"<br><br>0O11D 'N@A8'> 9'987 91D A:A'N <br><br>"J5

$6

/! rintlnI"<a href=V"catalog!htmlV"> ress 3717 to 1791D</a>"J5 M /! rintlnI"</body></html>"J5 M catchI7-ce tion eJ K res !send7rrorI;**Oe!to0tringIJJ5 M M M

$=

*r!er servlet:
*r!er.4ava:
im ort Ha)a!sBl!X5 im ort Ha)a!io!X5 im ort Ha)a-!ser)let!X5 im ort Ha)a-!ser)let!htt !X5 (blic class order e-tends 3tt 0er)let K (blic )oid ser)iceI3tt 0er)let1eB(est reBO3tt 0er)let1es onse res J thro/s 0er)let7-ce tionO'O7-ce tion K int co(nt5 .rintWriter /=res !getWriterIJ5 /! rintlnI"<html><body>"J5 0tring id=reB!get.arameterI"id"J5 0tring /d=reB!get.arameterI" /d"J5 0tring title=reB!get.arameterI"title"J5 0tring co(nt1=reB!get.arameterI"no"J5 0tring date=reB!get.arameterI"date"J5 0tring cno=reB!get.arameterI"cno"J5 try K co(nt='nteger! arse'ntIco(nt1J5 2lass!forNameI"s(n!Hdbc!odbc!?dbcOdbc>ri)er"J5 2onnection con=>ri)erManager!get2onnectionI"Hdbc,odbc,orcl"O"scott"O"ti ger"J5 0tatement stmt=con!create0tatementIJ5 0tring sBlstmt="select idO /d from login"5 1es(lt0et rs=stmt!e-ec(teA(eryIsBlstmtJ5 int flag=*Oamo(ntO-5 /hileIrs!ne-tIJJ K ifIid!eB(alsIrs!get0tringI1JJ44 /d!eB(alsIrs!get0tringI6JJJ K flag=15 M M ifIflag==*J K /! rintlnI"<br><br>0O11D 'N@A8'> '> 91D A:A'N '><br><br>"J5

$$

/! rintlnI"<a href= V" order!html V" > ress 3717 to 1791D</a>"J5 M else K 0tatement stmt6=con!create0tatementIJ5 0tring s="select cost from boo# /here title=VY"NtitleN"VY"5 1es(lt0et rs1=stmt6!e-ec(teA(eryIsJ5 int flag1=*5 /hileIrs1!ne-tIJJ K flag1=15 -='nteger! arse'ntIrs1!get0tringI1JJ5 amo(nt=co(ntX-5 /! rintlnI"<br><br>AMO+N9 ,"Namo(ntN"<br><br><br><br>"J5 0tatement stmt1=con!create0tatementIJ5 stmt1!e-ec(te+ dateI"insert into details )al(esIY"NidN"YOY"NtitleN"YO"Namo(ntN"OY"NcnoN"YJ 5"J5 /! rintlnI"<br>DO+1 O1>71 has ta#en<br>"J5 M ifIflag1==*J K /! rintlnI"<br><br><br>0O11D 'N@A8'> '> 91D A:A'N '><br><br>"J5 /! rintlnI"<a href=V"order!htmlV"> ress 3717 to 1791D</a>"J5 M M /! rintlnI"</body></html>"J5 con!closeIJ5 M catchI7-ce tion eJ K res !send7rrorI;**Oe!to0tringIJJ5 M M M

$;

5e#.2"l:
<T-ml )ersion="1!*"T> </ebUa > <ser)let> <ser)letUname>login</ser)letUname> <ser)letUclass>login</ser)letUclass> </ser)let> <ser)let> <ser)letUname>reg</ser)letUname> <ser)letUclass>reg</ser)letUclass> </ser)let> <ser)let> <ser)letUname> rofile</ser)letUname> <ser)letUclass> rofile</ser)letUclass> </ser)let> <ser)let> <ser)letUname>order</ser)letUname> <ser)letUclass>order</ser)letUclass> </ser)let> <ser)let> <ser)letUname>catalog</ser)letUname> <ser)letUclass>catalog</ser)letUclass> </ser)let> <ser)letUma ing> <ser)letUname>login</ser)letUname> <(rlU attern>/login</(rlU attern> </ser)letUma ing> <ser)letUma ing> <ser)letUname>reg</ser)letUname> <(rlU attern>/reg</(rlU attern> </ser)letUma ing> <ser)letUma ing> <ser)letUname> rofile</ser)letUname> <(rlU attern>/ rofile</(rlU attern> </ser)letUma ing> <ser)letUma ing> <ser)letUname>order</ser)letUname> <(rlU attern>/order</(rlU attern> </ser)letUma ing> <ser)letUma ing> <ser)letUname>catalog</ser)letUname> <(rlU attern>/catalog</(rlU attern> </ser)letUma ing> </elcomeUfileUlist> </elcomeUfile>main!html<//elcomeUfile> <//elcomeUfileUlist> <//ebUa >

$C

*utput:

Ho"e page:

$F

Login page:

$G

Login servlet:

$<

&egistration page:

&eg servlet:
;*

;1

'ser profile page:

)rofile servlet:
;6

;=

Books catalog page:

;$

+atalog servlet:

;;

( opping cart/ )ay"ent #y cre!it car!/ *r!er +onfor"ation page:

;C

*r!er servlet:

;F

6. AIM:
&e!o t e previous task using 0() #y converting t e static $e# pages of assign"ents - into !yna"ic $e# pages. +reate a !ata#ase $it user infor"ation an! #ooks infor"ation an! #ooks infor"ation. T e #ooks catalogue s oul! #e !yna"ically loa!e! fro" t e !ata#ase. 7ollo$ t e M.+ arc itecture $ ile !oing t e $e#site.

)&*+,D'&,:
1J 6J =J $J 2reate yo(r o/n directory (nder tomcat//eba s Ie!g! tr1J 2o y the html files in tr1 2o y the Hs files also into tr1 0tart tomcat gi)e the follo/ing command 2atalina!bat r(n At installUdir/bin ;J at '!7 gi)e (rl as htt ,//localhost,G*G1/tr1/main!html

Ho"e page:
Main. t"l:
<html> <body> <br><br><br><br><br><br> <h1 align="center"><(>ON8'N7 &OOE 09O1A:7</(></h1><br><br><br> <h6 align="center"><.17> <b> Welcome to online boo# storage! .ress 8O:'N if yo( are ha)ing id Other/ise ress 17:'091A9'ON </b></.17></h6> <br><br>< re> <di) align="center"><a href="login!html">8O:'N</a> <a href="reg!html">17:'091A9'ON</a></di)></ re> </body></html>

;G

Login page:
Login. t"l:
<html> <body><br /><br /><br /> <form name="myform" method=" ost" action="login!Hs "> <di) align="center">< re> 8O:'N '> ,<in (t ty e="te-t" name="id" /><br /> .A00WO1> ,<in (t ty e=" ass/ord" name=" /d" /></ re><br /><br /> </di)> <br /><br /> <di) align="center"> <in (t ty e="s(bmit" )al(e="o#" onclic#=")alidateIJ" /> 4nbs 54nbs 54nbs 54nbs 54nbs 54nbs 5<in (t ty e="reset" )al(e="clear" /> </di)> </form> </body> </html>

;<

&egistration page:
&eg. t"l:
<html> <body><br /><br /> <form name="myform" method=" ost" action="reg!Hs "> <table align="center" > <tr> <td>NAM7</td> <td>,<in (t ty e="te-t" name="name" /></td> </tr> <tr> <td>A>>1700</td> <td>,<in (t ty e="te-t" name="addr" /></td> </tr> <tr> <td>2ON9A29 N+M&71</td> <td>,<in (t ty e="te-t" name=" hno" /></td> </tr> <tr> <td>8O:'N'></td> <td>,<in (t ty e="te-t" name="id" /></td> </tr> <tr> <td>.A00WO1></td> <td>,<in (t ty e=" ass/ord" name=" /d" /></td> </tr> </table> <br /><br /> <di) align="center"> <in (t ty e="s(bmit" )al(e="o#" onclic#=")alidateIJ" /> 4nbs 54nbs 54nbs 54nbs 54nbs 54nbs 5<in (t ty e="reset" )al(e="clear" /> </di)> </form> </body> </html>

C*

'ser profile page:


)rofile. t"l:
<html> <body><br /><br /><br /> <form name="myform" method=" ost" action=" rofile!Hs "> <di) align="center">< re> 8O:'N '> ,<in (t ty e="te-t" name="id" /><br /> </ re><br /><br /> </di)> <br /><br /> <di) align="center"> <in (t ty e="s(bmit" )al(e="o#" onclic#=")alidateIJ" /> 4nbs 54nbs 54nbs 54nbs 54nbs 54nbs 5<in (t ty e="reset" )al(e="clear" /> </di)> </form> </body> </html>

Books catalog page:


+atalog. t"l:
<html> <body><br /><br /><br /> <form method=" ost" action="catalog!Hs "> <di) align="center">< re> &OOE 9'987 ,<in (t ty e="te-t" name="title" /><br /> </ re><br /><br /> </di)> <br /><br /> <di) align="center"> <in (t ty e="s(bmit" )al(e="o#" name="b(tton1"/>4nbs 54nbs 54nbs 54nbs 54nbs 54nbs 5 <in (t ty e="reset" )al(e="clear" name="b(tton6"/> </di)> </form> </body> </html>

C1

( opping cart/ )ay"ent #y cre!it car!/ *r!er +onfor"ation page:


*r!er. t"l:
<html> <body><br /><br /> <form method=" ost" action="order!Hs "> <di) align="center">< re> '> ,<in (t ty e="te-t" name="id" /><br /> .A00WO1> ,<in (t ty e=" ass/ord" name=" /d" /><br/> 9'987 ,<in (t ty e="te-t" name="title" /><br /> NO! O% &OOE0 ,<in (t ty e="te-t" name="no" /><br /> >A97 ,<in (t ty e="te-t" name="date" /><br /> 217>'9 2A1> N+M&71 ,<in (t ty e=" ass/ord" name="cno" /><br /></ re><br /><br /> </di)> <br /><br /> <di) align="center"> <in (t ty e="s(bmit" )al(e="o#" name="b(tton1"/> 4nbs 54nbs 54nbs 54nbs 54nbs 54nbs 5<in (t ty e="reset" )al(e="clear" name="b(tton6"/> </di)> </form> </body> </html>

C6

Login 0():
Login.4sp:
<Z[ age im ort="Ha)a!sBl!X"Z> <Z[ age im ort="Ha)a!io!X"Z> <Z o(t! rintlnI"<html><body>"J5 0tring id=reB(est!get.arameterI"id"J5 0tring /d=reB(est!get.arameterI" /d"J5 2lass!forNameI"s(n!Hdbc!odbc!?dbcOdbc>ri)er"J5 2onnection con=>ri)erManager!get2onnectionI"Hdbc,odbc,orcl"O"scott"O"tiger"J5 0tatement stmt=con!create0tatementIJ5 0tring sBlstmt="select idO /d from login"5 1es(lt0et rs=stmt!e-ec(teA(eryIsBlstmtJ5 int flag=*5 /hileIrs!ne-tIJJ K ifIid!eB(alsIrs!get0tringI1JJ44 /d!eB(alsIrs!get0tringI6JJJ K flag=15 M M ifIflag==*J K o(t! rintlnI"<br><br>0O11D 'N@A8'> '> 91D A:A'N '><br><br>"J5 o(t! rintlnI"<a href=V"login!htmlV"> ress 8O:'N to 1791D</a>"J5 M else K o(t! rintlnI"<br><br>@A8'> 8O:'N '><br><br>"J5 o(t! rintlnI"<h=><(l>"J5 o(t! rintlnI"<li><a href=V" rofile!htmlV"><fontcolor=V"blac#V">+071 .1O%'87</font> </a></li><br><br>"J5 o(t! rintlnI"<li><a href=V"catalog!htmlV"><fontcolor=V"blac#V">&OOE0 2A9A8O:</font></a></li><br><br>"J5 o(t! rintlnI"<li><a href=V"order!htmlV"><fontcolor=V"blac#V">O1>71 2ON%'1MA9'ON</font> </a></li></(l><br><br>"J5 M o(t! rintlnI"</body></html>"J5 con!closeIJ5 Z>

C=

&egistration 0():
&eg.4sp:
<Z[ age im ort="Ha)a!sBl!X"Z> <Z[ age im ort="Ha)a!io!X"Z> <Z res onse!set2ontent9y eI"te-t/html"J5 o(t! rintlnI"<html><body>"J5 0tring name=reB(est!get.arameterI"name"J5 0tring addr=reB(est!get.arameterI"addr"J5 0tring hno=reB(est!get.arameterI" hno"J5 0tring id1=reB(est!get.arameterI"id"J5 0tring /d1=reB(est!get.arameterI" /d"J5 int no='nteger! arse'ntI hnoJ5 2lass!forNameI"s(n!Hdbc!odbc!?dbcOdbc>ri)er"J5 2onnection con=>ri)erManager!get2onnectionI"Hdbc,odbc,orcl"O"scott"O"tiger"J5 0tatement stmt=con!create0tatementIJ5 0tring sBlstmt="select idO /d from login"5 1es(lt0et rs=stmt!e-ec(teA(eryIsBlstmtJ5 int flag=*5 /hileIrs!ne-tIJJ K ifIid1!eB(alsIrs!get0tringI1JJ44 /d1!eB(alsIrs!get0tringI6JJJ K flag=15 M M ifIflag==1J K o(t! rintlnI"<br><br>0O11D 'N@A8'> '> A817A>D 7Q'90 91D A:A'N W'93 N7W '><br><br>"J5 o(t! rintlnI"<a href=V"reg!htmlV"> ress 17:'0971 to 1791D</a>"J5 M else K 0tatement stmt1=con!create0tatementIJ5 stmt1!e-ec(te+ dateI"insert into login )al(esIY"NnameN"YOY"NaddrN"YO"NnoN"OY"Nid1N"YOY"N /d1N"YJ5 "J5 o(t! rintlnI"<br><br>DO+1 >79A'80 A17 7N9717><br><br>"J5 o(t! rintlnI"<a href=V"login!htmlV"> ress 8O:'N to login</a>"J5 M o(t! rintlnI"</body></html>"J5 con!closeIJ5 Z> C$

)rofile 0():
)rofile.4sp:
<Z[ age im ort="Ha)a!sBl!X"Z> <Z[ age im ort="Ha)a!io!X"Z> <Z o(t! rintlnI"<html><body>"J5 0tring id=reB(est!get.arameterI"id"J5 2lass!forNameI"s(n!Hdbc!odbc!?dbcOdbc>ri)er"J5 2onnection con=>ri)erManager!get2onnectionI"Hdbc,odbc,orcl"O"scott"O"tiger"J5 0tatement stmt=con!create0tatementIJ5 0tring sBlstmt="select X from login /here id="NidN""5 1es(lt0et rs=stmt!e-ec(teA(eryIsBlstmtJ5 int flag=*5 o(t! rintlnI"<br><br><br>"J5 /hileIrs!ne-tIJJ K o(t! rintlnI"<di) align=V"centerV">"J5 o(t! rintlnI"NAM7 ,"Nrs!get0tringI1JN"<br>"J5 o(t! rintlnI"A>>1700 ,"Nrs!get0tringI6JN"<br>"J5 o(t! rintlnI".3ON7 NO ,"Nrs!get0tringI=JN"<br>"J5 o(t! rintlnI"</di)>"J5 flag=15 M ifIflag==*J K o(t! rintlnI"<br><br>0O11D 'N@A8'> '> 91D A:A'N '><br><br>"J5 o(t! rintlnI"<a href=V" rofile!htmlV"> ress 3717 to 1791D</a>"J5 M o(t! rintlnI"</body></html>"J5 con!closeIJ5 Z>

C;

+atalog 0():
+atalog.4sp:
<Z[ age im ort="Ha)a!sBl!X"Z> <Z[ age im ort="Ha)a!io!X"Z> <Z o(t! rintlnI"<html><body>"J5 0tring title=reB(est!get.arameterI"title"J5 2lass!forNameI"s(n!Hdbc!odbc!?dbcOdbc>ri)er"J5 2onnection con=>ri)erManager!get2onnectionI"Hdbc,odbc,orcl"O"scott"O"tiger"J5 0tatement stmt=con!create0tatementIJ5 0tring sBlstmt="select X from boo# /here title=VY"NtitleN"VY"5 1es(lt0et rs=stmt!e-ec(teA(eryIsBlstmtJ5 int flag=*5 /hileIrs!ne-tIJJ K o(t! rintlnI"<di) align=V"centerV">"J5 o(t! rintlnI"9'987 ,"Nrs!get0tringI1JN"<br>"J5 o(t! rintlnI"A+93O1 ,"Nrs!get0tringI6JN"<br>"J5

o(t! rintlnI"@710'ON ,"Nrs!get0tringI=JN"<br>"J5 o(t! rintlnI".+&8'0371 ,"Nrs!get0tringI$JN"<br >"J5 o(t! rintlnI"2O09 ,"Nrs!get0tringI;JN"<br>"J5 o(t! rintlnI"</di)>"J5 flag=15 M ifIflag==*J K o(t! rintlnI"<br><br>0O11D 'N@A8'> 9'987 91D A:A'N <br><br>"J5 o(t! rintlnI"<a href=V"catalog!htmlV"> ress 3717 to 1791D</a>"J5 M o(t! rintlnI"</body></html>"J5 con!closeIJ5 Z>

CC

*r!er servlet:
*r!er.4ava:
<Z[ age im ort="Ha)a!sBl!X"Z> <Z[ age im ort="Ha)a!io!X"Z> <Z int co(nt5 o(t! rintlnI"<html><body>"J5 0tring id=reB(est!get.arameterI"id"J5 0tring /d=reB(est!get.arameterI" /d"J5 0tring title=reB(est!get.arameterI"title"J5 0tring co(nt1=reB(est!get.arameterI"no"J5 0tring date=reB(est!get.arameterI"date"J5 0tring cno=reB(est!get.arameterI"cno"J5 co(nt='nteger! arse'ntIco(nt1J5 2lass!forNameI"s(n!Hdbc!odbc!?dbcOdbc>ri)er"J5 2onnection con=>ri)erManager!get2onnectionI"Hdbc,odbc,orcl"O"scott"O"tiger"J5 0tatement stmt=con!create0tatementIJ5 0tring sBlstmt="select idO /d from login"5 1es(lt0et rs=stmt!e-ec(teA(eryIsBlstmtJ5 int flag=*Oamo(ntO-5 /hileIrs!ne-tIJJ K ifIid!eB(alsIrs!get0tringI1JJ44 /d!eB(alsIrs!get0tringI6JJJ K flag=15 M M ifIflag==*J K o(t! rintlnI"<br><br>0O11D 'N@A8'> '> 91D A:A'N '><br><br>"J5 o(t! rintlnI"<a href= V"order!html V" > ress 3717 to 1791D</a>"J5 M else K 0tatement stmt6=con!create0tatementIJ5 0tring s="select cost from boo# /here title=VY"NtitleN"VY"5 1es(lt0et rs1=stmt6!e-ec(teA(eryIsJ5 int flag1=*5 CF

/hileIrs1!ne-tIJJ K flag1=15 -='nteger! arse'ntIrs1!get0tringI1JJ5 amo(nt=co(ntX-5 o(t! rintlnI"<br><br>AMO+N9 ,"Namo(ntN"<br><br><br><br>"J5 0tatement stmt1=con!create0tatementIJ5 stmt1!e-ec(te+ dateI"insert into details )al(esIY"NidN"YOY"NtitleN"YO"Namo(ntN"OY"NcnoN"YJ 5"J5 o(t! rintlnI"<br>DO+1 O1>71 has ta#en<br>"J5 M ifIflag1==*J K o(t! rintlnI"<br><br><br>0O11D 'N@A8'> '> 91D A:A'N '><br><br>"J5 o(t! rintlnI"<a href=V"order!htmlV"> ress 3717 to 1791D</a>"J5 M M o(t! rintlnI"</body></html>"J5 con!closeIJ5 Z>

CG

*utput: Ho"e page:

C<

Login page:

F*

Login 0():

F1

&egistration page:

F6

&eg 0():

F=

'ser profile page:

F$

)rofile 0():

F;

Books catalog page:

FC

+atalog 0():

FF

( opping cart/ )ay"ent #y cre!it car!/ *r!er +onfor"ation page:

FG

*r!er 0():

F<

8.I"ple"ent t e 9Hello 5orl!:; progra" using 0() (truts 7ra"e$ork Hello5orl!.4sp


<Z[taglib (ri="/W7&U'N%/str(tsUbean!tld" refi-="bean" Z> <html> <head> <title>3ello World</title> </head> <body> <h1> <bean,/rite name="3elloWorldAction%orm" ro erty="message" /> </h1> </body> </html>

Hello5orl!Action.4ava
(blic class 3elloWorldAction e-tends org!a ache!str(ts!action!Action K ri)ate final static 0tring 0+22700 = "s(ccess"5 (blic Action%or/ard e-ec(teIActionMa ing ma ingOAction%orm formO3tt 0er)let1eB(est reB(estO3tt 0er)let1es onse res onseJ thro/s 7-ce tion K 3elloWorldAction%orm helloWorld%orm = I3elloWorldAction%ormJ form5 helloWorld%orm!setMessageI"3ello WorldP"J5 ret(rn ma ing!find%or/ardI0+22700J5 M M

struts<config.2"l file.
<str(tsUconfig>

<formUbeans> <formUbean name="3elloWorldAction%orm" ty e="com!)aannila!3elloWorldAction%orm"/>


G*

</formUbeans> <actionUma ings> <action in (t="/inde-!Hs " name="3elloWorldAction%orm" ath="/3elloWorld" sco e="session"
type="com.vaannila.HelloWorldAction"> <forward name="success" path="/helloWorld.jsp" /> </action> </action-mappin s> </struts-confi >

5e#.2"l
</elcomeUfileUlist> </elcomeUfile>inde-!Hs <//elcomeUfile> <//elcomeUfileUlist>

in!e2.4sp
<Hs ,for/ard age="3elloWorld!do"/>

Hello5orl!Action7or".4ava
(blic class 3elloWorldAction%orm e-tends org!a ache!str(ts!action!Action%orm
private "trin messa e# pu$lic HelloWorldAction%orm&'

K s( erIJ5 M (blic 0tring getMessageIJ K ret(rn message5 M (blic )oid setMessageI0tring messageJ K this!message = message5
( (

G1

&esult:

= AIM:
Bean Assign"ents G6

(a) +reate 4ava source file A!!erBean.4ava in A!!er !irectory (#) +reate a 0avaBean $ ic gives t e e2c ange value of I>&(In!ian &upees) into e?uivalent A"erican Dollar value. (c) +reate a si"ple Bean $it a la#el @ $ ic is t e count of nu"#er of clicks. T an create a BeanInfo class suc t at only t e 9count; property is !isa#le! in t e )roperty 5in!o$. (!) +reate t$o Beans Traffic Lig t(I"ple"ente! as a La#el $it only t ree #ackgroun! colours < &e!/ Areen/ Bello$) an! Auto"o#ile(I"ple"ente! as a Te2tBo2 $ ic states its stateC"ove"ent). T e state of t e Auto"o#ile s oul! !epen! on t e follo$ing Lig t Transition Ta#le. Lig t &e! Transition Auto"o#ile (tate <D Bello$ &ea!y Move (toppe!

Bello$ <D Areen Areen <D &e!

)&*+,D'&,:
IiJ IiiJ IiiiJ

2reate a directory 2reate Ha)a so(rce file 2ompile source file


create a manifest file enerate jar file start )*+

Ii)J I)J I)iJ


I)iiJ

test ne/ bean


BEANS

(a)ADDER

IiJ2reate a directory , create c,VbeansVdemoVs(n/VdemoVAdder directory! 2hange to that directory IiiJ 2reate Ha)a so(rce file Adder&ean!Ha)a in abo)e Adder directory ac#age s(n/!demo!Adder5 im ort Ha)a!a/t!X5 (blic class Adder&ean e-tends .anel K ri)ate do(ble a5
G=

ri)ate do(ble b5 ri)ate 9e-t%ield t=ne/ 9e-t%ieldIGJ5 (blic Adder&eanIJ K set8ayo(tIne/ &order8ayo(tIJJ5 addItO&order8ayo(t!27N971J5 M (blic do(ble addIJ Kret(rn aNb5 M (blic )oid setAIdo(ble -J K a=-5 t!set9e-tI>o(ble!to0tringIaddIJJJ5 M (blic do(ble getAIJ K ret(rn a5 M (blic )oid set&Ido(ble yJ K b=y5 t!set9e-tI>o(ble!to0tringIaddIJJJ5 M (blic do(ble get&IJ K ret(rn b5 M M IiiiJcom ile so(rce file goto command rom t and com ile c,VbeansVdemoVs(n/VdemoVAdder>Ha)ac Adder&ean!Ha)a Ii)Jcreate a manifest file Adder!mft in the Adder directory Name, s(n//demo/Adder/Adder&ean!class ?a)aU&ean, 9r(e I)Jgenerate Har fileO goto command rom t and re are Adder&ean!Har file and (t in Hars folder c,VbeansVdemo>Har cfm !!VHarsVAdder&ean!Har Adder!mft s(n/VdemoVAdderVX!class I)iJstart &>E goto c,VbeansVbeanbo- and do(ble clic# on r(n!bat file I)iiJtest ne/ bean clic# on Adder&ean b(tton in tool bo- and lace clic# on bean bo- areaO change ro erties aOb in ro erty bo-! No/ the res(lt /ill come in ne/ bean te-t bo-

G$

,-./012 )1A/ ,ounter.java pac3a e sunw.demo.wt# import java.awt.4# import java.io.4# pu$lic class ,ounter e5tends ,anvas implements "eriali6a$le ! private int count=7# pu$lic ,ounter&' !set"i6e&897:97'#( pu$lic void set,ount&int 5'!count=5#( pu$lic int et,ount&'!return count#( pu$lic void chan e&'!count;;# repaint&'#( pu$lic void paint&<raphics ' ! "trin str=",ounter ";count# .draw"trin &str:87:87'# ( ( &ii',ounter.mft /ame= sunw/demo/wt/,ounter.class >ava-)ean= 0rue 0est new $ean

G;

,lic3 on ,ounter $utton in tool $o5 and place clic3 on $ean $o5 area: clic3 on 0ic30oc3 $ean in tool $o5 and put on $ean $o5 . chan e the interval property in property $o5 to 8: now oto edit-> 1vents -> ?roperty,han e -> ?roperty,han e : red line comes ta3e it to counter $ean and clic3 on it now 1vent0ar et@ethod dialo $o5 comes choose chan e&' method: /ow the result will come in new counter area where the counter 7 chan es to counter 8 then counter A etc

(#)D*LLA& B,A> Dollar.4ava


pac3a e sunw.demo.wt# import java.awt.4# import java.io.4# pu$lic class *ollar e5tends ,anvas implements "eriali6a$le private int rupes=7#

GC

private dou$le dollar=7.7# pu$lic *ollar&' !set"i6e&897:97'#( pu$lic void set2upes&int 5'!rupes=5#repaint&'#( pu$lic int et2upes&'!return rupes#( pu$lic void chan e&'!dollar=rupes/97# repaint&'#( pu$lic void paint&<raphics ' ! "trin str8="2upes ";rupes# "trin strA="*ollars ";dollar# .draw"trin &str8:87:87'# .draw"trin &strA:87:A7'# ( (

Dollar."ft Name, s(n//demo//t/>ollar!class ?a)aU&ean, 9r(e Test ne$ #ean 2lic# on >ollar b(tton in tool bo- and lace clic# on bean bo- areaO clic# on 7- licit&(tton bean in tool bo- and (t on bean bo- ! goto ro erties and change label ro erty to con)ertO no/ goto editU>7)entsU>&(tton (shU >Action.erformed O red line comes ta#e it to dollar bean and clic# on it no/ 7)ent9argetMethod dialog bo- comes choose changeIJ methodO clic# on dollar bean goto ro erties and change r( ees ro erty to any )al(e li#e 6;*** O no/ clic# on con)ert b(tton the res(lt /ill come in ne/ dollar area /here the r( ees and dollars are dis layed

GF

(c)>u"#er of +licks

GG

)roce!ure: ?a)a %ile, 1!O en a note ad! 6!Write a Ha)a rogram that e-tends .anel and im lement Action8istener interface! =!Write coding to add a &(tton to the .anel and dis lay the n(mber of times a b(tton is clic#ed! $!9he action.erfomedIJ method increments the )al(e of co(nt /hen the &(tton is clic#ed! ;!0a)e the file as b(tton!Ha)a in a folder called co(nter! C!2om ile the b(tton!Ha)a file from its arent directory to generate the class file! c,VHa)a> Ha)ac co(nterVX!Ha)a Manifest %ile, 1!O en a note ad! 6!Write the manifest file to incl(de the name of the ?a)aU&ean class! I>on\t forget to add a carriage ret(rn and ne/line at the endJ 2reating the ?A1 file 1!O en the command rom t! 6!:o to the arent directory of the co(nter folder =!2reate the Har file! Ithe Har file sho(ld be in the Hars folder of the beanJ c,VHa)a> Har cfm c,VbeansVHarsVmyb(tton!Har co(nterVb(tton!mft co(nterVX!class &unning t e progra": 1!O en a command rom t! 6!:o to the directory /here beanbo- is resent I2,VbeansVbeanbo-J =!9y e r(n! $!9he bean /indo/s o ens! %rom the the 9ool bo- select the b(tton bean and dro it in the &ean&o-! ;!2lic# the b(tton in the bean to see the n(mber of clic#s made! .rogram,b(tton!Ha)a ac#age co(nter5
G<

im ort Ha)a!a/t!X5 im ort Ha)a!a/t!e)ent!X5 (blic class b(tton e-tends .anel im lements Action8istener K int co(nt5 &(tton b(t5 (blic b(ttonIJ K co(nt = *5 set0izeI6**O 1**J5 b(t = ne/ &(ttonI"2lic# me"J5 b(t!addAction8istenerIthisJ5 addIb(tJ5 M (blic )oid action.erformedIAction7)ent eJ K co(ntNN5 re aintIJ5 M (blic )oid aintI:ra hics gJ K >imension d = get0izeIJ5 %ont f=ne/ %ontI"2o(rier"O%ont!&O8>N%ont!'9A8'2O6$J5 int h = d!height5 int / = d!/idth5 g!set2olorI2olor! in#J5 g!fill1ectI*O *O /U1O hU1J5 g!set%ontIfJ5 g!set2olorIne/ 2olorI*O *O *JJ5 g!dra/0tringI"2lic# co(nt = " N co(ntO ;*O ;*J5 M M

Manifest file, b(tton!mft Name, co(nter!b(tton!class ?a)aU&ean, 9r(e

<*

*utput:

<1

(!)Traffic Lig ts
)roce!ure: 1! 2om ile 9raffic8ight!Ha)a by iss(ing the command Ha)ac ]d ! 9raffic8ight!Ha)a 6! 2om ile 9raffic.erson!Ha)a by iss(ing the command Ha)ac ]d ! 9raffic 9raffic.erson!Ha)a =! 2reate the 9raffic8ight!mft file $! 2reate the 9raffic.erson!mft file ;! 2reate 9raffic!Har &y iss(ing the command Har cfm 9raffic!Har 9raffic8ight!mft ac#agenameV9raffic8ight!class

Traffic Lig t. 0ava ac#age my ac#5 im im im im ort Ha)a!a/t!X5 ort Ha)a!beans!X5 ort Ha)a!io!X5 ort Ha)a!(til!>ate5

(blic class 9raffic8ight e-tends .anel im lements 1(nnableO 0erializableO .ro erty2hange8istener K (blic 9raffic8ightIJ K set0izeI;*O ;*J5 color = 2olor!red5 label = ne/ 8abelIJ5 label!set0izeI1**O1**J5 label!set&ac#gro(ndI2olor!redJ5 addIlabelJ5 changes = ne/ .ro erty2hange0( ortIthisJ5 changes!add.ro erty2hange8istenerIthisJ5 inter)al = ;5 r(nner = ne/ 9hreadIthisJ5 r(nner!startIJ5 M

<6

(blic )oid add.ro erty2hange8istenerI.ro erty2hange8istener ro ertychangelistenerJ K changes!add.ro erty2hange8istenerI ro ertychangelistenerJ5 M (blic )oid remo)e.ro erty2hange8istenerI.ro erty2hange8istener ro ertychangelistenerJ K changes!remo)e.ro erty2hange8istenerI ro ertychangelistenerJ5 M

(blic int get'nter)alIJ K ret(rn inter)al5 M (blic )oid set'nter)alIint iJ K inter)al = i5 ifIr(nner P= n(llJ r(nner!interr( tIJ5 M (blic int get0econdsIJ K ret(rn IintJIIne/ >ateIJJ!get9imeIJ / 1***8J5 M (blic )oid r(nIJ K int i = get0econdsIJ5 do K try K 9hread!slee Iinter)al X 1***J5 M catchI'nterr( ted7-ce tion interr( tede-ce tionJ K M int H = get0econdsIJ5

<=

changes!fire.ro erty2hangeI"seconds"O ne/ 'ntegerIiJO ne/ 'ntegerIHJJ5 i = H5 M /hileItr(eJ5 M (blic )oid ro erty2hangeI.ro erty2hange7)ent ro ertychangee)entJ K ifIcolor == 2olor!redJ K label!set&ac#gro(ndI2olor!orangeJ5 color = 2olor!orange5 M else ifIcolor == 2olor!orangeJ K label!set&ac#gro(ndI2olor!greenJ5 color = 2olor!green5 M else ifIcolor == 2olor!greenJ K label!set&ac#gro(ndI2olor!redJ5 color = 2olor!red5 M M ri)ate 2olor color5 ri)ate 8abel label5 ri)ate .ro erty2hange0( ri)ate int inter)al5 transient 9hread r(nner5 M TrafficLig t.M7T file ManifestU@ersion, 1!* Name, my ac#/9raffic8ight!class ?a)aU&ean, 9r(e

ort changes5

<$

You might also like