You are on page 1of 124

Week-1 Date: 23-06-08

------------------------------------------------------------------------------------------------------------
AIM: Design the static web pages required for an online book store web site.
1) HOME PAGE
DESCRIPTION:
The static home page must contain three frames.
Top frame : Logo and the college name and links to Home page, Login page,
Registration page,
Left frame : At least four links for naigation, which will displa! the catalogue of
respectie links.
"or e.g.: #hen !ou click the link ~CSE the catalogue for CSE $ooks should be
displa!ed in the Right frame.
Right frame: The pages to the links in the left frame must be loaded here. %nitiall!
this page contains description of the web site.
PROGRAM:
Homepage
<head>
<frameset rows="20%,*">
<frame src="topframe.html"name="f1">
<frameset cols="20%,*">
<frame src="leftframe.html"name="f2">
<frame src="rightframe.html"name="f3">
</frameset>
</frameset>
</head>
&rasad '. &otluri (iddhartha %nstitute of Technolog! )
OUTPUT:
Top frame:
<html>
<od!>
<p>
<img src=""#$%oc&ments and 'ettings$(ll )sers$%oc&ments$*! +ict&res$'ample
+ict&res$,inter.-pg" align=left width=100 height=100">
<h1 align=center>.nline oo/ store</h1>
</p>
<r>
<p>
<h2>0nsp1nsp10nsp10nsp1
&rasad '. &otluri (iddhartha %nstitute of Technolog! *
<a href="homepage.html" target=2parent>
3ome
</a>
0nsp10nsp10nsp10nsp1 0nsp10nsp10nsp10nsp1
<a href="login.html" target="f3">
login
</a>
0nsp10nsp10nsp10nsp10nsp10nsp10nsp10nsp1
<a href="registration.html" target="f3">
registration
</a>
0nsp10nsp10nsp10nsp10nsp1nsp10nsp10nsp1
<a href="catalog&e.html" target="f3">
"atalog&e
</a>
0nsp10nsp10nsp10nsp10nsp10nsp10nsp10nsp1
<a href="cart.html" target="f3">
"art
</a>
0nsp1
</h2>
</p>
</od!>
</html>
&rasad '. &otluri (iddhartha %nstitute of Technolog! +
OUTPUT:
Leftframe:
<html>
<od!>
<a href=cse.html target="f3"><h3>"'4</h3> </a><r><r><r><r><r>
<a href=ece.html target="f3"><h3>4"4</h3></a><r><r><r><r><r>
<a href=eee.html target="f3"><h3>444</h3></a><r><r><r><r><r>
<a href=ci5il.html target="f3"><h3>"i5il</h3></a>
</od!>
</html>
&rasad '. &otluri (iddhartha %nstitute of Technolog! ,
OUTPUT:
Right frame:
<html>
<od! gcolor="pin/">
<p>
<h2 align="center"> <font face="times new roman" color="green" >.nline oo/ store
information </font> </h2>
<h3> 0nsp1 0nsp1 0nsp1 0nsp1 0nsp1<font face="monot!pe corsi5a" color=l&e> 6his is
the online oo/ store de5eloped ! st&dents of p5psit.7t contains oo/ catalog&e of 5ario&s
ranches li/e cse,ece,eee,ci5il </font></h3>
</p>
&rasad '. &otluri (iddhartha %nstitute of Technolog! -
</od!>
</html>
OUTPUT:
2) LOGIN PAGE
DESCRIPTION:
The login page contains the user name and the password of the user to
authenticate.
PROGRAM:
<html>
<head>
<p st!le= "ac/gro&nd#!ellow1 top#100p81 left#290p81 position#asol&te1 ">
</head>
<od! ac/gro&nd=:4#$1.-pg:>
<form action="inde8.-sp" method="get">
&rasad '. &otluri (iddhartha %nstitute of Technolog! .
<lael> 0nsp10nsp10nsp10nsp10nsp10nsp1
<font face="comic sans ms" color="green" si;e="9"><ogin </font>
</lael> 0nsp10nsp10nsp10nsp1
<inp&t t!pe="te8t" si;e="20" ma8length="20" 5al&e== =><r><r><r>
<lael>
<font face="comic sans ms" color="green" si;e="9">+assword </font> </lael>
<inp&t t!pe="password" si;e="20" ma8length="20"> <r><r><r> 0nsp1 0nsp1
0nsp10nsp1 0nsp1 0nsp10nsp1
<inp&t t!pe="s&mit" 5al&e="s&mit">0nsp10nsp10nsp10nsp10nsp1
<inp&t t!pe="reset">
</form>
</od!>
</html>
OUTPUT:
&rasad '. &otluri (iddhartha %nstitute of Technolog! /
3) CATOLOGUE PAGE
DESCRIPTION:
The catalogue page should contain the details of all the books aailable in the web
site in a table.
The details should contain the following:
). (nap shot of 0oer &age.
&rasad '. &otluri (iddhartha %nstitute of Technolog! 1
*. Author 2ame.
+. &ublisher.
,. &rice.
-. Add to cart button.
PROGRAM:
<html>
<od!>
<center>
<tale order=1>
<tr>
<th> >oo/ +re5iew </th>
<th> >oo/ %etails </th>
<th> +rice </th>
<th> +a!ment </th>
</tr>
<tr>
<td> <img src=""#$%oc&ments and 'ettings$(ll &sers$*! %oc&ments$*! +ict&res$8ml.mp"
width=100 height=90>
</img>
</td>
<td>
<pre>
<font face="comic sans ms" si;e=? color="green" >
oo/#@*< >ile
(&thor#winston
+&lisher#,iesle!
</font>
</pre>
</td>
<td>0nsp1A?0 0nsp1 </td>
&rasad '. &otluri (iddhartha %nstitute of Technolog! 3
<td> 0nsp1 0nsp1 <a href="cart.html" target="2lan/">
<img src=""#$%oc&ments and 'ettings$(ll &sers$*! %oc&ments$*! +ict&res$cart.mp"
width="190" height="100"></img>
</a> 0nsp1 0nsp1
</td>
</tr>
<tr>
<td> <img src=""#$%oc&ments and 'ettings$(ll &sers$*! %oc&ments$*! +ict&res$-a5a.mp"
width=100 height=90>
</img>
</td>
<td>
<pre>
<font face="comic sans ms" si;e=? color="green" >
oo/#Ba5a 2
(&thor#,atson
+&lisher#>+> p&lications
</font>
</pre>
</td>
<td>0nsp1 A?0 0nsp1</td>
<td> 0nsp1 0nsp1 <a href="cart.html" target="2lan/">
<img src=""#$%oc&ments and 'ettings$(ll &sers$*! %oc&ments$*! +ict&res$cart.mp"
width="190" height="100"></img>
</a> 0nsp1 0nsp1
</td>
</tr>
</tale> </center>
</od!>
</html>
OUTPUT:
&rasad '. &otluri (iddhartha %nstitute of Technolog! )4

&rasad '. &otluri (iddhartha %nstitute of Technolog! ))
RESULT:
Thus the home page, login page, catalogue page for the online book store are
created successfull!
&rasad '. &otluri (iddhartha %nstitute of Technolog! )*
Week-2 Date: 30-06-08
------------------------------------------------------------------------------------------------------------
AIM: Design of the cart page and the registration page required for online book store.
4) CART PAGE
DESCRIPTION:
The cart page contains the details about the books which are added to the cart.
PROGRAM:
<html>
<od!>
<center><r><r><r>
<img src=:4#$aa.-pg:>
<tale order=1 cellpadding=center>
<thead>
<tr>
<th>>oo/ name</th>
<th>price</th>
<th>C&antit!</th>
<th>amo&nt</th>
</tr>
</thead>
<tr>
<td>-a5a 2</td>
<td>A?9</td>
<td>2</td>
<td>AD0</td>
</tr>
<tr>
<td> @*< ile</td>
&rasad '. &otluri (iddhartha %nstitute of Technolog! )+
<td> A20</td>
<td> 9</td>
<td> A?0</td>
</tr>
<th colspan=?>total amo&nt=A110>
</th>
</tr>
</tale>
</center>
</od!>
</html>
OUTPUT:
&rasad '. &otluri (iddhartha %nstitute of Technolog! ),
5) REGISTRATION PAGE
DESCRIPTION:
0reate a 5registration form 5with the following fields
)62ame7Te8tfield6
*6 &assword 7password field6
+6 9:mail id 7te8t field6
,6 &hone number 7te8t field6
-6 (e8 7radio button6
.6 Date of birth 7+ select bo8es6
/6 Languages known 7check bo8es ; 9nglish, Telugu, Hindi, Tamil6
16 Address 7te8t area6
PROGRAM:
<html>
<od!>
<center>
<img src=:4#$aaa.-pg: align=:left:>
<form>
<lael>name</lael>
<inp&t t!pe="te8t" si;e="20"><r><r> <r>
<lael>password</lael>
<inp&t t!pe="password" si;e="20" ma8si;e="2E"><r> <r> <r>
<lael>email</lael>
<inp&t t!pe="te8t" si;e="30"><r> <r> <r>
<lael>phone no</lael>
<inp&t t!pe="te8t" si;e="2">
<inp&t t!pe="te8t" si;e="F">
<inp&t t!pe="te8t" si;e="10"><r> <r> <r>
<lael>'e8</lael>
<inp&t t!pe="radio" name="se8">m
&rasad '. &otluri (iddhartha %nstitute of Technolog! )-
<inp&t t!pe="radio" name="se8">f <r> <r> <r>
<lael> date of irth</lael>
<select>
<option>1</option>
<option>2</option>
<option>3</option>
<option>?</option>
<option>9</option>
</select>
<select>
<option>-an</option>
<option>fe</option>
<option>mar</option>
<option>apr</option>
</select>
<select>
<option>1GE0</option>
<option>1GE1</option>
<option>1GE2</option>
<option>1GE3</option>
</select> <r> <r> <r>
<lael> <ang&ages Hnown </lael> 0nsp1 0nsp1
<inp&t t!pe="chec/o8"> 4nglish 0nsp1 0nsp10nsp1
<inp&t t!pe="chec/o8"> 6el&g& 0nsp1 0nsp1 0nsp1
<inp&t t!pe="chec/o8"> 3indi 0nsp1 0nsp1 0nsp1
<inp&t t!pe="chec/o8"> 6amil <r> <r> <r>
<lael> (ddress </lael>
<te8tarea rows=9 cols=20 scrolling="!es"> </te8tarea>
</center>
</od!>
</html>
&rasad '. &otluri (iddhartha %nstitute of Technolog! ).

OUTPUT:

RESULT:
Thus the registration and cart pages for online book store pages are created
successfull!
&rasad '. &otluri (iddhartha %nstitute of Technolog! )/
Week-3 Date: 14-07-08
------------------------------------------------------------------------------------------------------------
AIM: #rite JavaScript to alidate the following fields of the aboe registration page.
). 2ame 72ame should contains alphabets and the length should not be less than
. characters6.
*. &assword 7&assword should not be less than . characters length6.
+. 9:mail id 7should not contain an! inalid and must follow the standard pattern
name<domain.com6
,. &hone number 7&hone number should contain )4 digits onl!6.
DESCRIPTION:
=aa(cript is a simple scripting language inented specificall! for use in web
browsers to make websites more d!namic. >n its own, HT?L is capable of outputting
more:or:less static pages. >nce !ou load them up !our iew doesn@t change much until
!ou click a link to go to a new page. Adding =aa(cript to !our code allows !ou to
change how the document looks completel!, from changing te8t, to changing colors, to
changing the options aailable in a drop:down list. =aa(cript is a client-side language.
=aa(cripts are integrated into the browsing enironment, which means the! can
get information about the browser and HT?L page, and modif! this information, thus
changing how things are presented on !our screen. This access to information gies
=aa(cript great power to modif! the browsing e8perience. The! can also react to events,
such as when the user clicks their mouse, or points to a certain page element. This is also
a er! powerful abilit!.
Regular Expressions:
>ne of the most common situations that come up is haing an HT?L form for
users to enter data. 2ormall!, we might be interested in the isitorAs name, phone number
and email address, and so forth. Howeer, een if we are er! careful about putting some
hints ne8t to each required field, some isitors are going to get it wrong, either
accidentall! or for malicious purposes. HereAs where regular e8pressions come in hand!.
A regular e8pression is a wa! of describing a pattern in a piece of te8t. %n fact, itAs an eas!
&rasad '. &otluri (iddhartha %nstitute of Technolog! )1
wa! of matching a string to a pattern. #e could write a simple regular e8pression and use
it to check, quickl!, whether or not an! gien string is a properl! formatted user input.
This saes us from difficulties and allows us to write clean and tight code.
A regular e8pression is a =aa(cript obBect. There are multiple wa!s of creating
them. The! can be created staticall! when the script is first parsed or d!namicall! at run
time. A static regular e8pression is created as follows:
reg8CDfishEfow)DF
D!namic patterns are created using the ke!word to create an instance of the
Reg98p class:
reg8Cnew Reg98p75fishEfow)G6F
Functions:
test(string)- Tests a string for pattern matches. This method returns a $oolean that
indicates whether or not the specified pattern e8ists within the searched string. This is the
most commonl! used method for alidation. %t updates some of the properties of the
parent Reg98p obBect following a successful search.
exec(string): 98ecutes a search for a pattern within a string. %f the pattern is not found,
e8ec76 returns a null alue. %f it finds one or more matches it returns an arra! of the match
results. %t also updates some of the properties of the parent Reg98p obBect
PROGRAM:
Valid.js
function fun76
H
ar userCdocument.formsI4J.user.alueF
ar pwdCdocument.formsI4J.pwd.alueF
ar emailCdocument.formsI4J.email.alueF
ar phCdocument.formsI4J.ph.alueF
ar userregCnew Reg98p7KLIa:MA:NJIa:MA:N4:3JOPK6F
ar emailregCnew Reg98p7KLIa:MA:NJIa:MA:N4:3Q.JO<Ia:MA:NJIa:MA:N4:3Q.JO.
Ia:MA:NJIa:MA:N4:3Q.JH*R.Ia:MA:NJIa:MA:N4:3Q.JH*RPELIa:MA:NJIa:MA:N4:3Q.JO<Ia:MA:
NJIa:MA:N4:3Q.JO.Ia:MA:NJIa:MA:N4:3Q.JH+RPK6F
ar phregCnew Reg98p7KLI4:3JH)4RPK6F
ar ruserCuserreg.e8ec7user6F
ar remailCemailreg.e8ec7email6F
&rasad '. &otluri (iddhartha %nstitute of Technolog! )3
ar rphCphreg.e8ec7ph6F
if7ruser SS remail SS rph SS 7pwd.length T .66
H
alert7KAll alues are alidK6F
return trueF
R
else
H
if7Uruser6 H alert7Kusername inalidK6Fdocument.formsI4J.user.focus76FR
if7Uremail6 H alert7Kpassword inalidK6Fdocument.formsI4J.user.focus76FR
if7Urph6 H alert7Kphone number inalidK6Fdocument.formsI4J.ph.focus76FR
if7pwd.length V .6 H alert7Kpassword inalidK6Fdocument.formsI4J.pwd.focus76FR
return falseF
R
R
Register.html
VhtmlT
Vbod!T
VcenterT
VfieldsetT
VlegendTRegistrationVDlegendT
Vform actionCKDatabaseK methodCKgetK on(ubmitCKreturn fun76KT
VpreT
2ame :Vinput t!peCKte8tK nameCKuserK siMeCK)4KTVbrT
&assword :Vinput t!peCKpasswordK nameCKpwdK siMeCK)4KTVbrT
9:mail :Vinput t!peCKte8tK nameCKemailK siMeCK)4KTVbrT
&hone 2umber :Vinput t!peCKte8tK nameCKphK siMeCK)4KTVbrT
Vinput t!peCKsubmitK alueCKRegisterKT
VDpreT
VDformT
VDbod!T
Vscript srcCKalid.BsKTVDscriptT
VDhtmlT
OUTPUT:

&rasad '. &otluri (iddhartha %nstitute of Technolog! *4
&rasad '. &otluri (iddhartha %nstitute of Technolog! *)
RESULT:
Thus the home page, login page, catalogue page for the online book store are
created successfull!
&rasad '. &otluri (iddhartha %nstitute of Technolog! **
Week-4 Date: 21-07-08
------------------------------------------------------------------------------------------------------------
AIM:
Design a web page using CSS (Cascading St!le Sheets) which includes the
following:
1) Wse different font, st!les: %n the st!le definition !ou define how each selector
should work .Then, in the bod! of !our pages, !ou refer to these selectors to
actiate the st!les.
2) (et a background image for both the page and single elements on the page.
3) 0ontrol the repetition of the image with the background:repeat propert!
DESCRIPTION:
Cascading Style Sheets 7CSS6 is a st!lesheet language used to describe the
presentation of a document written in a markup language. %ts most common application is
to st!le web pages written in HT?L and XHT?L, but the language can be applied to an!
kind of X?L document.
%n 0((, selectors are used to declare which elements a st!le applies to, a kind of match
e8pression. (electors ma! appl! to all elements of a specific t!pe, or onl! those elements
which match a certain attributeF elements ma! be matched depending on how the! are
placed relatie to each other in the markup code, or on how the! are nested within the
document obBect model
A st!le sheet consists of a list of rules. 9ach rule or rule:set consists of one or
more selectors and a declaration block. A declaration:block consists of a list of
semicolon:separated declarations in braces. 9ach declaration itself consists of a property,
a colon 7:6, a value, then a semi:colon 7;6
Yenerall! speaking we can sa! that all the st!les will KcascadeK into a new KirtualK
st!le sheet b! the following rules:
&rasad '. &otluri (iddhartha %nstitute of Technolog! *+
). 98ternal st!le sheet
*. %nternal st!le sheet 7inside the VheadT tag6
+. %nline st!le 7inside an HT?L element6
An inline st!le 7inside an HT?L element6 has the highest priorit!, which means that
it will oerride a st!le declared inside the VheadT tag, in an e8ternal st!le sheet, or in a
browser 7a default alue6.
Syntax
The 0(( s!nta8 is made up of three parts: a selector, a propert! and a alue:
selector Hpropert!: alueR
The selector is normall! the HT?L elementDtag !ou wish to define, the propert! is the
attribute !ou wish to change, and each propert! can take a alue. The propert! and alue
are separated b! a colon, and surrounded b! curl! braces:
bod! Hcolor: blackR
External Style Sheet
An e8ternal st!le sheet is ideal when the st!le is applied to man! pages. #ith an
e8ternal st!le sheet, !ou can change the look of an entire #eb site b! changing one file.
9ach page must link to the st!le sheet using the VlinkT tag. The VlinkT tag goes inside
the head section:
VheadT
Vlink relCKst!lesheetK t!peCKte8tDcssK
hrefCKm!st!le.cssK DT
VDheadT
The browser will read the st!le definitions from the file m!st!le.css, and format the
document according to it.
Internal Style Sheet
An internal st!le sheet should be used when a single document has a unique st!le.
Zou define internal st!les in the head section b! using the Vst!leT tag,
VheadT
Vst!leT
selector Hpropert!:alueF propert!:alueF[..R
&rasad '. &otluri (iddhartha %nstitute of Technolog! *,
VDst!leT
VDheadT
Inline Styles
An inline st!le loses man! of the adantages of st!le sheets b! mi8ing content
with presentation. Wse this method sparingl!, such as when a st!le is to be applied to a
single occurrence of an element.
To use inline st!les !ou use the st!le attribute in the releant tag. The st!le attribute can
contain an! 0(( propert!.
Vp st!leCKcolor: siennaF margin:left: *4p8KT
This is a paragraph VDpT
PROGRAM:
Cas.css:
a#lin/Icolor#lac/1J
a#5isitedIcolor#pin/1J
a#acti5eIcolor#red1J
a#ho5erIcolor#green1J
.right I
te8tKalign#center1
te8tKdecoration#&nderline1
fontKweight#old1
color#l&e1
fontKfamil!#comic sans ms1
fontKsi;e#301 J
.image I
te8tKalign#left1
fontKfamil!#"monot!pe corsi5a"1
fontKweight#101
J
&rasad '. &otluri (iddhartha %nstitute of Technolog! *-

.image1 I
ac/gro&ndKimage#&rlL""#$%oc&ments and 'ettings$(ll )sers$*! %oc&ments$*!
+ict&res$/rishna.-pg"M1
ac/gro&ndKattachment#fi8ed1
ac/gro&ndKrepeat#noKrepeat1
width#1901
height#1901 J
tale I align#center1order#101
orderKst!le#ridge1
orderKcolor#!ellow1J
htm.html:
<html>
<head>
<lin/ rel="st!lesheet" href="cas.css" t!pe="te8t/css">
<st!le>
.8lin/I te8tKdecoration#none1fontKweight#old1c&rsor#crosshair1J
.!lin/Ite8tKdecoration#&nderline1fontKweight#old1c&rsor#help1J
</st!le>
</head>
<od! class="image">
<p st!le="te8tKalign#right1">
<a href="registration.html" class="8lin/"> Neg <in/</a>0nsp10nsp1
<a href="topframe.html" class="!lin/"> 3elp <in/</a>
</p>
<p class="right">+O+'76</p>
<di5 st!le="position#relati5e1fontKsi;e#G0p81;Kinde8#91color#p&rple1">+O+'76</di5>
<di5 st!le="position#relati5e1fontKsi;e#90p81;Kinde8#11top#KD01 left#91color#l&e1">"'4</di5>
<di5 st!le="position#relati5e1fontKsi;e#G0p81;Kinde8#11color#p&rple1">+O+'76</di5>
&rasad '. &otluri (iddhartha %nstitute of Technolog! *.
<di5 st!le="position#relati5e1fontKsi;e#90p81;Kinde8#91top#KD01 left#91color#l&e1">"'4</di5>
<tale align="center" class="image1">
<tr>
<td> Pr&its</td>
<td> *ango</td>
</tr>
</tale>
</od!>
</html>
OUTPUT:
RESULT: Thus different st!le of 0(( and different t!pe of the properties are applied.
&rasad '. &otluri (iddhartha %nstitute of Technolog! */
Week-5: Date: 28-07-08
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
AIM: #rite an X?L file which will displa! the $ook information.
%t includes the following:
)6 Title of the book
*6 Author 2ame
+6 %($2 number
,6 &ublisher name
-6 9dition
.6 &rice
#rite a Document T!pe Definition 7DTD6 to alidate the aboe X?L file.
Displa! the X?L file as follows.
The contents should be displa!ed in a table. The header of the table should be in color
YR9Z. And the Author names column should be displa!ed in one color and should be
capitaliMed and in bold. Wse !our own colors for remaining columns.
Wse X?L schemas X(L and 0(( for the aboe purpose.
DESCRIPTION:
DTD vs XML Schema
The DTD proides a basic grammar for defining an X?L Document in terms of
the metadata that comprise the shape of the document. An X?L (chema proides this,
plus a detailed wa! to define what the data can and cannot contain. %t proides far more
control for the deeloper oer what is legal, and it proides an >bBect >riented approach,
with all the benefits this entails.
?an! s!stems interfaces are alread! defined as a DTD. The! are mature
definitions, rich and comple8. The effort in re:writing the definition ma! not be
worthwhile.
DTD is also established, and e8amples of common obBects defined in a DTD abound on
the %nternet :: freel! aailable for re:use. A deeloper ma! be able to use these to define a
&rasad '. &otluri (iddhartha %nstitute of Technolog! *1
DTD more quickl! than the! would be able to accomplish a complete re:deelopment of
the core elements as a new schema.
"inall!, !ou must also consider the fact that the X?L (chema is an X?L
document. %t has an X?L 2amespace to refer to, and an X?L DTD to define it. This is
all oerhead. #hen a parser e8amines the document, it ma! hae to link this all in,
interpret the DTD for the (chema, load the namespace, and alidate the schema, etc., all
before it can parse the actual X?L document in question. %f !ou@re using X?L as a
protocol between two s!stems that are in hea! use, and need a quick response, then this
oerhead ma! seriousl! degrade performance.
Write a Document Type Definition (DTD) to validate the XML file.
PROGRAM:
XML document (bookstore.xml)
<bookstore>
<book>
<title>web programming</title>
<author>chrisbates</author>
<ISBN>123-456-789</ISBN>
<publisher>wiley</publisher>
<edition>3</edition>
<price>350</price>
</book>
<book>
<title>internet worldwideweb</title>
<author>ditel&amp;ditel</author>
<ISBN>123-456-781</ISBN>
<publisher>person</publisher>
<edition>3</edition>
<price>450</price>
</book>
</bookstore>
XML document Validation using DTD
DTD document (bookstore.dtd)
V\8ml ersionCK).4K encodingCKWT":1K\T
VU9L9?92T bookstore 7book]6T
VU9L9?92T book 7title,author,%($2,publisher,edition,price6T
&rasad '. &otluri (iddhartha %nstitute of Technolog! *3
VU9L9?92T title 7^&0DATA6T
VU9L9?92T author 7^&0DATA6T
VU9L9?92T %($2 7^&0DATA6T
VU9L9?92T publisher 7^&0DATA6T
VU9L9?92T edition 7^&0DATA6T
VU9L9?92T price 7^&0DATA6T
Bookstore.xml
<!DOCTYPE bookstore SYSTEM "C:\Documents and Settings\Administrator\My
Documents\bookstore.dtd">
VbookstoreT
VbookT
VtitleTweb programmingVDtitleT
VauthorTchrisbatesVDauthorT
V%($2T)*+:,-.:/13VD%($2T
VpublisherTwile!VDpublisherT
VeditionT+VDeditionT
VpriceT+-4VDpriceT
VDbookT
VbookT
VtitleTinternet worldwidewebVDtitleT
VauthorTditelSampFditelVDauthorT
V%($2T)*+:,-.:/1)VD%($2T
VpublisherTpersonVDpublisherT
VeditionT+VDeditionT
VpriceT,-4VDpriceT
VDbookT
VDbookstoreT
XML document Validation using DTD
XML Schema (bookstore.xsd)
V\8ml ersionCK).4K encodingCKWT":1K\T
<xs:schema elementFormDefault"qualified" attributeFormDefault"unqualified"
xmlns:xs"http://www.w3.org/2001/XMLSchema">
V8s:element nameCKbookstoreKT
V8s:comple8T!peT
V8s:sequenceT
V8s:element nameCKbookK ma8>ccursCKunboundedKT
V8s:comple8T!peT
V8s:sequenceT
V8s:element nameCKtitleK t!peCK8s:stringKTVD8s:elementT
&rasad '. &otluri (iddhartha %nstitute of Technolog! +4
V8s:element nameCKauthorK t!peCK8s:stringKTVD8s:elementT
V8s:element nameCK%($2K t!peCK8s:stringKTVD8s:elementT
V8s:element nameCKpublisherK t!peCK8s:stringKTVD8s:elementT
V8s:element nameCKeditionK t!peCK8s:intKTVD8s:elementT
V8s:element nameCKpriceK t!peCK8s:decimalKTVD8s:elementT
VD8s:sequenceT
VD8s:comple8T!peT
VD8s:elementT
VD8s:sequenceT
VD8s:comple8T!peT
VD8s:elementT
VD8s:schemaT
Bookstore.xml
<bookstore xmlns:xsi"http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation"C:\Documents and Settings\Administrator\My
Documents\bookstore.xsd">
VbookT
VtitleTweb programmingVDtitleT
VauthorTchrisbatesVDauthorT
V%($2T)*+:,-.:/13VD%($2T
VpublisherTwile!VDpublisherT
VeditionT+VDeditionT
VpriceT+-4VDpriceT
VDbookT
VbookT
VtitleTinternet worldwidewebVDtitleT
VauthorTditelSampFditelVDauthorT
V%($2T)*+:,-.:/1)VD%($2T
VpublisherTpersonVDpublisherT
VeditionT+VDeditionT
VpriceT,-4VDpriceT
VDbookT
VDbookstoreT
Display the XML file as follows.
PROGRAM:
XML:
<Q8ml 5ersion="1.0"Q>
&rasad '. &otluri (iddhartha %nstitute of Technolog! +)
<Q8mlKst!lesheet t!pe="te8t/8sl" href="oo/store.8sl"Q>
<oo/store>
<oo/>
<title>45er!da! 7talian</title>
<a&thor>Riada %e <a&rentiis</a&thor>
<!ear>2009</!ear>
<price>30.00</price>
</oo/>
<oo/>
<title>3arr! +otter</title>
<a&thor>B H. Nowling</a&thor>
<!ear>2009</!ear>
<price>2G.GG</price>
</oo/>
<oo/>
<title><earning @*<</title>
<a&thor>4ri/ 6. Na!</a&thor>
<!ear>2003</!ear>
<price>3G.G9</price>
</oo/>
</oo/store>
XSL:
<8sl#st!lesheet 5ersion="1.0" 8mlns#8sl="http#//www.w3.org/1GGG/@'</6ransform">
<8sl#template match="/">
<html>
<od!>
<h2> *! >oo/s collection</h2>
<tale order="1">
<tr gcolor="red">
<th align="left">title</th>
&rasad '. &otluri (iddhartha %nstitute of Technolog! +*
<th align="left">a&thor</th>
</tr>
<8sl#forKeach select="oo/store/oo/">
<tr>
<td><8sl#5al&eKof select="title"/></td>
<8sl#choose>
<8sl#when test="price 0gt1 30">
<td gcolor="!ellow"><8sl#5al&eKof select="a&thor"/></td>
</8sl#when>
<8sl#when test="price 0gt1 10">
<td gcolor="magneta"><8sl#5al&eKof select="a&thor"/></td>
</8sl#when>
<8sl#otherwise>
<td><8sl#5al&eKof select="a&thor"/></td>
</8sl#otherwise>
</8sl#choose>
</tr>
</8sl#forKeach>
</tale>
</od!>
</html>
</8sl#template>
</8sl#st!lesheet>
OUTPUT:
&rasad '. &otluri (iddhartha %nstitute of Technolog! ++
RESULT: Thus the X?L st!lesheets are successfull! used to displa! the content in a
table format.
Week-6: Date: 04-08-08
------------------------------------------------------------------------------------------------------------
VISUAL BEANS:
AIM: 0reate a simple isual bean with a area filled with a color.
The shape of the area depends on the propert! shape. %f it is set to true then the
shape of the area is (quare and it is 0ircle, if it is false.
The color of the area should be changed d!namicall! for eer! mouse click. The color
should also be changed if we change the color in the 5propert! window 5.
DESCRIPTION:
A $ean is a =aa$eans component. $eans are independent, reusable software
modules. $eans ma! be isible obBects, like A#T components, or inisible obBects, like
queues and stacks. A builderDintegration tool manipulates $eans to create applets and
applications.
$eans consist of three things:
&rasad '. &otluri (iddhartha %nstitute of Technolog! +,
Events
An eent allows !our $eans to communicate when something interesting
happens. There are three parts to this communication:
9ent>bBect
9ent Listener : 7the sink6
An 9ent (ource 7the $ean6
The eent source defines when and where an eent will happen. 0lasses register
themseles as interested in the eent, and the! receie notification when the eent
happens. A series of methods patterns represents the registration process:
public s!nchroniMed oid addListenerT!pe7ListenerT!pe l6F
public s!nchroniMed oid remoeListenerT!pe7 ListenerT!pe l6F
Properties
&roperties define the characteristics of the $ean. "or instance, when e8amining an A#T
Te8t"ield for its properties, !ou will see properties for the caret position, current te8t, and
the echo character, among others. A propert! is a public attribute of the $ean, usuall!
represented b! a non:public instance ariable. %t can be read:write, read:onl!, or write:
onl!. There are four different t!pes of properties:
Simple - As the name implies, simple properties represent the simplest of the four.
To create a propert!, define a pair of setDget routines. #hateer name used in the
pair of routines, becomes the propert! name
Indexed - An inde8ed propert! is for when a single propert! can hold an arra! of
alues. The design pattern for these properties is:
public oid set&ropert!2ame 7&ropert!T!peIJ list6
public oid set&ropert!2ame 7
&ropert!T!pe element, int position6
public &ropert!T!peIJ get&ropert!2ame 76
public &ropert!T!pe get&ropert!2ame 7int position6
Bound - A bean that has the bound propert! generates an eent when the propert!
is changed. The eent is of t!pe propertyChangeEvent and is sent to obBects that
preiousl! registered an interest in receieing such notifications. %n order for the
notification to happen, !ou need to maintain a watch list for
&rasad '. &otluri (iddhartha %nstitute of Technolog! +-
PropertyChangeEvents ia the PropertyChangeSupport class. "irst,
!ou hae to create a list of listeners to maintain:
priate &ropert!0hange(upport changes C
new &ropert!0hange(upport 7this6F
And then, !ou hae to maintain the list:
public oid add&ropert!0hangeListener 7
&ropert!0hangeListener p6 H
changes.add&ropert!0hangeListener 7p6F
R
public oid remoe&ropert!0hangeListener 7
&ropert!0hangeListener p6 H
changes.remoe&ropert!0hangeListener 7p6F
R
Constrained - 0onstrained properties are similar to bound properties. %n addition
to maintaining a list of &ropert!0hangeListeners, the $ean maintains a list of
VetoableChangeListeners. Then, prior to the $ean changing a propert!
alue, it asks the 'etoable0hangeListeners if its oka!. %f it isn@t, the listener
throws a PropertyVetoException, which !ou declare the set routine to
throw.
Methods
$ean methods are aailable for an!one to call b! Bust making each public.
Howeer, !ou can restrict which methods are isible to the $ean builderDintegration tool
b! proiding a get?ethodDescriptors method along with !our $ean@s $ean%nfo. 9er!
$ean can proide a supporting $ean%nfo class to customiMe a $ean@s appearance to an
integration tool.
Procedural Steps to create a 1ava-Bean:
)6 0reating a director!: 0reate a new director! in 0:_beans_demo_sunw_demo with
a new folder name colors
*6 0reate a Baa source file
+6 0ompile the Baa source file
,6 0reate a manifest file colors.mft in the director! called as 0:_beans_demo
&rasad '. &otluri (iddhartha %nstitute of Technolog! +.
-6 0reate a Bar file: to create a Bar file t!pe the following command in the command
prompt
Bar cfm .._Bars_colors.Bar colors.mft sunw_demo_colors_O.class
.6 (tart the $D`
/6 0heck whether the colors bean is placed in toolbo8 or not.
PROGRAM:
pac/age s&nw.demo.colors1
import -a5a.awt.*1
import -a5a.awt.e5ent.*1
p&lic class "olors e8tends "an5as
I
transient pri5ate "olor color1
pri5ate oolean rectang&lar1
p&lic "olorsLM
I
add*o&se<istenerLnew *o&se(dapterLMI
p&lic 5oid mo&se+ressedL*o&se45ent meMI
changeLM1 J
JM1
rectang&lar=false1
set'i;eL100,100M1
changeLM1
J
p&lic oolean getNectang&larLM
I
ret&rn rectang&lar1
J
p&lic 5oid setNectang&larLoolean flagM
I
this.rectang&lar=flag1
&rasad '. &otluri (iddhartha %nstitute of Technolog! +/
repaintLM1
J
p&lic 5oid changeLM
I
color=random"olorLM1
repaintLM1
J
pri5ate "olor random"olorLM
I
int r=LintML299**ath.randomLMM1
int g=LintML299**ath.randomLMM1
int =LintML299**ath.randomLMM1
ret&rn new "olorLr,g,M1
J
p&lic 5oid paintLRraphics gM
I
%imension d=get'i;eLM1
int h=d.height1
int w=d.width1
g.set"olorLcolorM1
ifLrectang&larM
I
g.fillNectL0,0,wK1,hK1M1
J
else
I
g.fill.5alL0,0,wK1,hK1M1
J
J
J
&rasad '. &otluri (iddhartha %nstitute of Technolog! +1
OUTPUT:
RESULT:
&rasad '. &otluri (iddhartha %nstitute of Technolog! +3
Thus the colors bean is created successfull!.
Program 2:
Visual Beans (program 2)
Convert.java
package sunw.demo.convert;
import java.awt.`;
import java.awt.event.`;
public class convert extends Canvas

private double dollars0.0;


private double rupees0.0;
private double dollarvalue0.0;
public convert()

setSize(100,1000);
]
public double getDollars()

return dollars;
]
public void setDollars(double value)

this.dollarsvalue;
]
public void setRupees(double value)

this.rupeesvalue;
]
public double getRupees()

return rupees;
]
public void change()

dollarvalue value();
repaint();
]
private double value()

return rupees`dollars;
]
&rasad '. &otluri (iddhartha %nstitute of Technolog! ,4
public void paint(Graphics g)

g.setColor(Color.red);
g.drawString(String.valueOf(dollarvalue),10,10);
]
]
Convert.mf
Name: sunw/demo/convert/convert.class
1ava-Bean: True ( press Enter)
(Carriage return compulsory)
&rasad '. &otluri (iddhartha %nstitute of Technolog! ,)
Result
Thus the conertion bean is created successfull!
Program 3:
package sunw.demo.colors;
import java.awt.`;
import java.awt.event.`;
public class mouseclick extends Canvas
public int count0;
public mouseclick()
addMouseListener(new MouseAdapter()
public void mousePressed(MouseEvent me)
change();
]
]);
&rasad '. &otluri (iddhartha %nstitute of Technolog! ,*
setSize(100,100);
]
public void change()
count++;
repaint();
]
public void paint(Graphics g)
Dimension d getSize();
int h d.height;
int w d.width;
g.setColor(Color.red);
g.fillRect(0,0,100,100);
g.setColor(Color.blue);
g.drawString(String.valueOf(count),50,50);
]
]
Mouseclick.mft
Name: sunw/demo/colors/mouseclick.class
1ava-Bean: True
Output
&rasad '. &otluri (iddhartha %nstitute of Technolog! ,+
Result
Thus the ?ouse 0licks bean is created successfull!
Week-7: Date: 11-08-08
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
AIM: %nstall T>?0AT web serer and A&A0H9.
#hile installation assign port number 1414 to A&A0H9. ?ake sure that these ports are
aailable i.e., no other process is using this port.
DESCRIPTION:
&rasad '. &otluri (iddhartha %nstitute of Technolog! ,,
Set the 1AVA_HOME Variable
Zou must set the JAVA_HOME enironment ariable to tell Tomcat where to find
=aa. "ailing to properl! set this ariable preents Tomcat from handling =(& pages. This
ariable should list the base =D` installation director!, not the bin subdirector!.
>n #indows X&, !ou could also go to the (tart menu, select 0ontrol &anel, choose
(!stem, click on the Adanced tab, press the 9nironment 'ariables button at the bottom,
and enter the JAVA_HOME ariable and alue directl! as:
2ame: =A'AQH>?9
'alue: 0:_Bdk
Set the CLASSPATH
(ince serlets and =(& are not part of the =aa * platform, standard edition, !ou
hae to identif! the serlet classes to the compiler. The serer alread! knows about the
serlet classes, but the compiler 7i.e., javac6 !ou use for deelopment probabl! doesn@t.
(o, if !ou don@t set !our CLASSPATH, attempts to compile serlets, tag libraries, or other
classes that use the serlet and =(& A&%s will fail with error messages about unknown
classes.
2ame: =A'AQH>?9
'alue: install_dir/common/lib/servlet-api!ar
Turn on Servlet Reloading
The ne8t step is to tell Tomcat to check the modification dates of the class files of
requested serlets and reload ones that hae changed since the! were loaded into the
serer@s memor!. This slightl! degrades performance in deplo!ment situations, so is
turned off b! default. Howeer, if !ou fail to turn it on for !our deelopment serer,
!ou@ll hae to restart the serer eer! time !ou recompile a serlet that has alread! been
loaded into the serer@s memor!.
To turn on serlet reloading, edit install_dir/conf/server"ml and add a DefaultContext
subelement to the main Host element and suppl! true for the reloadable attribute. "or
e8ample, in Tomcat -.4.*/, search for this entr!:
&rasad '. &otluri (iddhartha %nstitute of Technolog! ,-
VHost nameCKlocalhostK debugCK4K app$aseCKwebappsK ...T
and then insert the following immediatel! below it:
VDefault0onte8t reloadableCKtrueKDT
$e sure to make a backup cop! of server"ml before making the aboe change.
Enable the Invoker Servlet
The inoker serlet lets !ou run serlets without first making changes to !our
#eb application@s deplo!ment descriptor. %nstead, !ou Bust drop !our serlet into #E$-
%&'/classes and use the WRL http://host/servlet/Servlet&ame. The inoker serlet is
e8tremel! conenient when !ou are learning and een when !ou are doing !our initial
deelopment.
To enable the inoker serlet, uncomment the following servlet and servlet-
a!!"n# elements in install_dir/conf/(eb"ml. "inall!, remember to make a backup cop!
of the original ersion of this file before !ou make the changes.
<ser5let>
<ser5letKname>in5o/er</ser5letKname>
<ser5letKclass>
org.apache.catalina.ser5lets.7n5o/er'er5let
</ser5letKclass>
...
</ser5let>
...
<ser5letKmapping>
<ser5letKname>in5o/er</ser5letKname>
<&rlKpattern>/ser5let/*</&rlKpattern>
</ser5letKmapping>
OUTPUT$
&rasad '. &otluri (iddhartha %nstitute of Technolog! ,.

RESULT: Thus T>?0AT web serer was installed successfull!.
Week-7: Date: 11-08-08
&rasad '. &otluri (iddhartha %nstitute of Technolog! ,/
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
AIM: Access the deeloped static web pages for books web site, using these serers b!
putting the web pages deeloped in week:) and week:* in the document root.
OUTPUT
&rasad '. &otluri (iddhartha %nstitute of Technolog! ,1
RESULT:
Thus week:) and week:* pages are accessed using the T>?0AT web serer successfull!.
Week-8: Date: 10-09-08
&rasad '. &otluri (iddhartha %nstitute of Technolog! ,3
------------------------------------------------------------------------------------------------------------
AIM:
User Authentication:
Assume four users user), user*, user+ and user, haing the passwords pwd),
pwd*, pwd+ and pwd, respectiel!. #rite a serelet for doing the following.
). 0reate a 0ookie and add these four user idAs and passwords to this 0ookie.
*. Read the user id and passwords entered in the Login form 7week)6 and
authenticate with the alues 7user id and passwords6 aailable in the cookies.
%f he is a alid user 7i.e., user:name and password match6 !ou should welcome
him b! name 7user:name6 else !ou should displa! 5Zou are not an
authenticated user 5. Wse init:parameters to do this. (tore the user:names and
passwords in the web.8ml and access them in the serlet b! using the
get%nit&arameters76 method.
DESCRIPTION:
Servlet Life cycle:
) Servlet class loading
* Servlet %nstantiation
+ call the init method
, call the service method
- call destroy method
Class loading and instantiation
%f !ou consider a serlet to be Bust like an! other =aa program, e8cept that it runs
within a serlet container, there has to be a process of loading the class and making it
read! for requests. (erlets do not hae the e8act equialent of a main method that causes
them to start e8ecution.
#hen a web container starts it searches for the deplo!ment descriptor
7#9$.X?L6 for each of its web applications. #hen it finds a serlet in the descriptor it
will create an instance of the serlet class. At this point the class is considered to be
loaded 7but not initialiMed6.
&rasad '. &otluri (iddhartha %nstitute of Technolog! -4
The init method
The Http(erlet class inherits the init method from Yeneric(erlet. The init
method performs a role slightl! similar to a constructor in an 5ordinar!G =aa program in
that it allows initialiMation of an instance at start up. %t is called automaticall! b! the
serlet container and as it causes the application conte8t 7#9$.X?L6 to be parsed and
an! initialiMation will be performed. %t comes in two ersions, one with a Mero parameter
constructor and one that takes a (erlet0onfig parameter.
The serlet engine creates a request obBect and a response obBect. The serlet engine
inokes the serlet serice76 method, passing the request and response obBects. >nce the
init method returns the serlet is said to be placed into serice. The process of using init
to initialiMe serlets means that it is possible to change configuration details b! modif!ing
the deplo!ment descriptor without haing them hard coded in with !our =aa source and
needing a re:compilation.
oid init7(erlet0onfig sc6
Calling the service method
The serice76 method gets information about the request from the request obBect,
processes the request, and uses methods of the response obBect to create the client
response. The serice method can inoke other methods to process the request, such as
doYet76, do&ost76, or methods !ou write. The serice method is called for each request
processed and is not normall! oerridden b! the programmer.
The code that makes a serlet 5goG is the. serlet
oid serice7(erletRequest req,(erletResponse res6
The destroy Method
Two t!pical reasons for the destro! method being called are if the container is
shutting down or if the container is low on resources. This can happen when the container
keeps a pool of instances of serlets to ensure adequate performance. %f no requests hae
come in for a particular serlet for a while it ma! destro! it to ensure resources are
aailable for the serlets that are being requested. The destro! method is called onl!
once, before a serlet is unloaded and thus !ou cannot be certain when and if it is called.
oid destro!76
&rasad '. &otluri (iddhartha %nstitute of Technolog! -)
ServletConfig Class
ServletConf"# obBect is used b! the (erlet 0ontainer to pass information to the
(erlet during it@s initialiMation. (erlet can obtain information regarding initialiMation
parameters and their alues using different methods of ServletConf"# class
initialiMation parameters are nameDalue pairs used to proide basic information to the
(erlet during it@s initialiMation like =D$0 drier name, path to database, username,
password etc.
Methods of ServletConfig class
"ollowing are the four methods of this class :
getInitParameter(String paramName) Returns alue of the gien parameter. %f
alue of parameter could not be found in web.8ml file then a null alue is
returned.
getInitParameterNames() Returns an Enuerat"on obBect containing all the
names of initialiMation parameters proided for this (erlet.
getServletContext() Returns reference to the ServletContext obBect for this
(erlet. %t is similar to #etServletContext%& method proided b! Htt!Servlet
class.
getServletName() Returns name of the (erlet as proided in the web.8ml file or
if none is proided then returns complete class path to the (erlet.
PROGRAM:
cologin.html:
<html>
<head>
<title> login +age </title>
<p st!le= "ac/gro&nd#!ellow1 top#100p81 left#290p81 position#asol&te1 ">
</head>
<od!>
<form ("67.S="clogin">
&rasad '. &otluri (iddhartha %nstitute of Technolog! -*
<lael> <ogin </lael>
<inp&t t!pe="te8t" name="&sr" si;e="20"> <r> <r>
<lael> +assword </lael>
<inp&t t!pe="password" name="pwd" si;e="20"> <r> <r>
<inp&t t!pe="s&mit" 5al&e="s&mit">
</form>
</od!>
</html>
cologin1.html
<html>
<head>
<title> login +age </title>
<p st!le= "ac/gro&nd#!ellow1 top#100p81 left#290p81 position#asol&te1 ">
</head>
<od!>
<form ("67.S="clogin1">
<lael> <ogin </lael>
<inp&t t!pe="te8t" name="&sr" si;e="20"> <r> <r>
<lael> +assword </lael>
<inp&t t!pe="password" name="pwd" si;e="20"> <r> <r>
<inp&t t!pe="s&mit" 5al&e="s&mit">
</form>
</od!>
</html>
Addcook.java:
import -a5a8.ser5let.* 1
import -a5a8.ser5let.http.*1
import -a5a.io.*1
p&lic class (ddcoo/ e8tends 3ttp'er5let
I
&rasad '. &otluri (iddhartha %nstitute of Technolog! -+
'tring &ser,pas1
p&lic 5oid ser5iceL3ttp'er5letNeC&est reC,3ttp'er5letNesponse resM throws
'er5let48ception,7.48ception
I
res.set"ontent6!peL"te8t/html"M1
+rint,riter o&t=res.get,riterLM1
"oo/ie c1=new "oo/ieL"&sr1","s&ni"M1
"oo/ie p1=new "oo/ieL"pwd1","ani"M1
"oo/ie c2=new "oo/ieL"&sr2","ac"M1
"oo/ie p2=new "oo/ieL"pwd2","123"M1
"oo/ie c3=new "oo/ieL"&sr3","def"M1
"oo/ie p3=new "oo/ieL"pwd3","?9F"M1
"oo/ie c?=new "oo/ieL"&sr?","mno"M1
"oo/ie p?=new "oo/ieL"pwd?","DEG"M1
res.add"oo/ieLc1M1
res.add"oo/ieLp1M1
res.add"oo/ieLc2M1
res.add"oo/ieLp2M1
res.add"oo/ieLc3M1
res.add"oo/ieLp3M1
res.add"oo/ieLc?M1
res.add"oo/ieLp?M1
o&t.printlnL""..H74 (%%4%"M1
J
J
Clogin.java:
import -a5a8.ser5let.* 1
import -a5a8.ser5let.http.*1
import -a5a.io.*1
p&lic class "login e8tends 3ttp'er5let
I
&rasad '. &otluri (iddhartha %nstitute of Technolog! -,
'tring &ser,pas1
p&lic 5oid ser5iceL3ttp'er5letNeC&est reC,3ttp'er5letNesponse resM throws
'er5let48ception,7.48ception
I
res.set"ontent6!peL"te8t/html"M1
+rint,riter o&t=res.get,riterLM1
&ser=reC.get+arameterL"&sr"M1
pas=reC.get+arameterL"pwd"M1
"oo/ieTU c=reC.get"oo/iesLM1
forLint i=01i<c.length1iVVM
I
ifLLcTiU.getSameLM.eC&alsL"&sr1"M00cTiV1U.getSameLM.eC&alsL"pwd1"MMWW cTiU.getSameLM.eC&alsL"&sr2"M
00cTiV1U.getSameLM.eC&alsL"pwd2"MMWWLcTiU.getSameLM.eC&alsL"&sr3"M00
cTiV1U.getSameLM.eC&alsL"pwd3"MMWWLcTiU.getSameLM.eC&alsL"&sr?"M00
cTiV1U.getSameLM.eC&alsL"pwd?"M MM
I
ifLL&ser.eC&alsLcTiU.getOal&eLMM 00 pas.eC&alsLcTiV1U.getOal&eLMMM M
I
//NeC&est%ispatcher rd=reC.getNeC&est%ispatcherL"/cart.html"M1
rd.forwardLreC,resM1
J
else
I
o&t.printlnL"X.) (N4 S.6 ()63.N7'4% )'4N "M1
//res.sendNedirectL"/coo/demo/cologin.html"M1
J
J
J
J
J
&rasad '. &otluri (iddhartha %nstitute of Technolog! --
Web.xml:
<weKapp>
<ser5let>
<ser5letKname>him</ser5letKname>
<ser5letKclass>"login</ser5letKclass>
</ser5let>
<ser5let>
<ser5letKname>him1</ser5letKname>
<ser5letKclass>(ddcoo/</ser5letKclass>
</ser5let>
<ser5letKmapping>
<ser5letKname>him</ser5letKname>
<&rlKpattern>/clogin</&rlKpattern>
</ser5letKmapping>
<ser5letKmapping>
<ser5letKname>him1</ser5letKname>
<&rlKpattern>/clogin1</&rlKpattern>
</ser5letKmapping>
</weKapp>
OUTPUT:
&rasad '. &otluri (iddhartha %nstitute of Technolog! -.
&rasad '. &otluri (iddhartha %nstitute of Technolog! -/
*. Read the user id and passwords entered in the Login form 7week)6 and authenticate
with the alues 7user id and passwords6 aailable in the cookies.
%f he is a alid user 7i.e., user:name and password match6 !ou should welcome him b!
name 7user:name6 else !ou should displa! 5Zou are not an authenticated user 5.
Wse init:parameters to do this. (tore the user:names and passwords in the webinf.8ml and
access them in the serlet b! using the get%nit&arameters76 method.
home.html:
<html>
<head>
<title>(&thentication</title>
</head>
<od!>
<form action="e81">
<lael>)sername </lael>
<inp&t t!pe="te8t"si;e="20" name="&ser"><r><r>
password<inp&t t!pe="te8t" si;e="20" name="pwd"><r><r>
<inp&t t!pe="s&mit" 5al&e="s&mit">
</form>
&rasad '. &otluri (iddhartha %nstitute of Technolog! -1
</od!>
</html>
Example1.java
import -a5a8.ser5let.*1
import -a5a.io.*1
p&lic class 48ample1 e8tends Reneric'er5let
I
pri5ate 'tring &ser1,pwd1,&ser2,pwd2,&ser3,pwd3,&ser?,pwd?,&ser9,pwd91
p&lic 5oid initL'er5let"onfig scM
I
&ser1=sc.get7nit+arameterL"&sername1"M1
pwd1=sc.get7nit+arameterL"password1"M1
&ser2=sc.get7nit+arameterL"&sername2"M1
pwd2=sc.get7nit+arameterL"password2"M1
&ser3=sc.get7nit+arameterL"&sername3"M1
pwd3=sc.get7nit+arameterL"password3"M1
&ser?=sc.get7nit+arameterL"&sername?"M1
pwd?=sc.get7nit+arameterL"password?"M1
J
+&lic 5oid ser5iceL'er5letNeC&est reC,'er5letNesponse resMthrows
'er5let48ception,7.48ception
I
res.set"ontent6!peL"te8t/html"M1
+rint,riter o&t=res.get,riterLM1
&ser9=reC.get+arameterL"&ser"M1
pwd9=reC.get+arameterL"pwd"M1
ifLL&ser9.eC&alsL&ser1M00pwd9.eC&alsLpwd1MMWWL&ser9.eC&alsL&ser2M00pwd9.eC&alsLpwd2MMWW
L&ser9.eC&alsL&ser3M00pwd9.eC&alsLpwd3MMWWL&ser9.eC&alsL&ser?M00pwd9.eC&alsLpwd?MMM
&rasad '. &otluri (iddhartha %nstitute of Technolog! -3
o&t.printlnL"<p> welcome to"V&ser9.to)pper"aseLMM1
else
o&t.printlnL"Xo& are not a&thori;ed &ser"M1
J
J
web.xml:
<weKapp>
<ser5let>
<ser5letKname>48ample</ser5letKname>
<ser5letKclass>48ample1</ser5letKclass>
<initKparam>
<paramKname>&sername1</paramKname>
<paramK5al&e>p5psit</paramK5al&e>
</initKparam>
<initKparam>
<paramKname>password1</paramKname>
<paramK5al&e>cse</paramK5al&e>
</initKparam>
<initKparam>
<paramKname>&sername2</paramKname>
<paramK5al&e>123?</paramK5al&e>
</initKparam>
<initKparam>
<paramKname>password2</paramKname>
<paramK5al&e>?9FD</paramK5al&e>
</initKparam>
<initKparam>
<paramKname>&sername3</paramKname>
<paramK5al&e>cse</paramK5al&e>
</initKparam>
&rasad '. &otluri (iddhartha %nstitute of Technolog! .4
<initKparam>
<paramKname>password3</paramKname>
<paramK5al&e>p5psit</paramK5al&e>
</initKparam>
<initKparam>
<paramKname>&sername?</paramKname>
<paramK5al&e>wt</paramK5al&e>
</initKparam>
<initKparam>
<paramKname>password?</paramKname>
<paramK5al&e>la</paramK5al&e>
</initKparam>
</ser5let>
<ser5letKmapping>
<ser5letKname>48ample</ser5letKname>
<&rlKpattern>/e81</&rlKpattern>
</ser5letKmapping>
</weKapp>
OUTPUT:
&rasad '. &otluri (iddhartha %nstitute of Technolog! .)
RESULT:
Thus the user authentication is carried out for four users b! using both cookies
and get%nit&arameters successfull!.
Week-9 Date: 22-09-08
&rasad '. &otluri (iddhartha %nstitute of Technolog! .*
------------------------------------------------------------------------------------------------------------
AIM: %nstall a database 7?!sql or >racle6.
0reate a table which should contain at least the following fields: name, password,
email:id, phone number 7these should hold the data from the registration form6.
&ractice @=D$0@ connectiit!.
#rite a Baa programDserletD=(& to connect to that database and e8tract data from the
tables and displa! them. 98periment with arious (aL queries.
%nsert the details of the users who register with the web site, wheneer a new user clicks
the submit button in the registration page 7week*6.
DESCRIPTION:
1DBC Driver Types
There are four t!pes of =D$0 driers in use:
Type 1: JDBC-ODBC Bridge
A T!pe ) =D$0:>D$0 $ridge proides application deelopers with a wa! to
access =D$0 driers ia the =D$0 A&%. T!pe ) =D$0 driers translate the =D$0 calls
into >D$0 calls and then send the calls to the >D$0 drier. T!pe ) =D$0 driers are
generall! used when the database client libraries need to be loaded on eer! client
machine.
Type 2: Native API/Partly Java Driver
A T!pe * 2atie A&%D&artl! =aa Drier is a partial =aa drier because it conerts
=D$0 calls into database specific calls. T!pe * 2atie A&%D&artl! =aa Drier
communicates directl! with the database serer.
Type 3: Pure Java Driver
A T!pe + &ure =aa Drier works in a three tiered architecture. The =D$0 calls
are passed ia the network to the middle tier serer. This serer translates the calls to the
database specific natie interface to further request the serer. =D$0 driers aailable
from (imba are T!pe + driers.
Type 4: Native Protool Java Driver
&rasad '. &otluri (iddhartha %nstitute of Technolog! .+
The t!pe , drier is written completel! in =aa and is hence platform independent.
%t is installed inside the =aa 'irtual ?achine of the client. %t proides better performance
oer the t!pe ) and * driers as it does not hae the oerhead of conersion of calls into
>D$0 or database A&% calls. Wnlike the t!pe + driers, it does not need associated
software to work.A T!pe , 2atie &rotocol =aa Drier conerts =D$0 calls into the
database specific calls so that the client applications can communicate directl! with the
serer.
PROGRAM:
Registration.html:
<html>
<head>
<title>Negistration page</title>
</head>
<od! gcolor="Y00PPPf">
<form *463.%="+.'6" ("67.S="register">
<"4S64N>
<tale>
<center>
<tr> <td> )sername </td>
<td><inp&t t!pe="te8t" name="&sr"> </td> </tr>
<tr><td> +assword </td>
<td><inp&t t!pe="password" name="pwd"> </td> </tr>
<tr><td>(ge</td>
<td><inp&t t!pe="te8t" name="age"> </td> </tr>
<tr> <td>(ddress</td>
<td> <inp&t t!pe="te8t" name="add"> </td> </tr>
<tr> <td>email</td>
<td> <inp&t t!pe="te8t" name="mail"> </td> </tr>
<tr> <td>+hone</td>
<td> <inp&t t!pe="te8t" name="phone"> </td> </tr>
&rasad '. &otluri (iddhartha %nstitute of Technolog! .,
<tr> <td colspan=2 align=center> <inp&t t!pe="s&mit" 5al&e="s&mit"> </td> </tr>
</center>
</tale>
</form>
</od!>
Login.html
<html>
<head>
<title>Negistration page</title>
</head>
<od! gcolor=pin/> <center> <tale>
<form *463.%="+.'6" ("67.S="a&thent">
<tr> <td> )sername </td>
<td><inp&t t!pe="te8t" name="&sr"></td> </tr>
<tr> <td> +assword </td>
<td> <inp&t t!pe="password" name="pwd"> </td> </tr>
<tr> <td align=center colspan="2"><inp&t t!pe="s&mit" 5al&e="s&mit"></td> </tr>
</tale> </center>
</form>
</od!>
</html>

Ini.java:
import -a5a8.ser5let.*1
import -a5a.sCl.*1
import -a5a.io.*1
p&lic class 7ni e8tends Reneric'er5let
I
pri5ate 'tring &ser1,pwd1,email11
&rasad '. &otluri (iddhartha %nstitute of Technolog! .-
p&lic 5oid ser5iceL'er5letNeC&est reC,'er5letNesponse resM throws 'er5let48ception,7.48ception
I
&ser1=reC.get+arameterL"&ser"M1
pwd1=reC.get+arameterL"pwd"M1
email1=reC.get+arameterL"email"M1
res.set"ontent6!peL"te8t/html"M1
+rint,riter o&t=res.get,riterLM1
tr!
I
"lass.forSameL"oracle.-dc.dri5er..racle%ri5er"M1
"onnection
con=%ri5er*anager.get"onnectionL"-dc#oracle#thin#Z1G9.100.101.19E#1921#ccla","scott","tiger"M1
+repared'tatement st=con.prepare'tatementL"insert into personal 5al&esLQ,Q,Q,Q,Q,QM"M1
st.set'tringL1,&ser1M1
st.set'tringL2,pwd1M1
st.set'tringL3,"29"M1
st.set'tringL?,"h!d"M1
st.set'tringL9,email1M1
st.set'tringLF,"2123?"M1
st.e8ec&te)pdateLM1
con.closeLM1
J
catchL'[<48ception sM
I o&t.printlnL"not fo&nd "VsM1
J
catchL"lassSotPo&nd48ception cM
I
o&t.printlnL"not fo&nd "VcM1
J
J J
&rasad '. &otluri (iddhartha %nstitute of Technolog! ..
web.xml:
<weKapp>
<ser5let>
<ser5letKname>init1</ser5letKname>
<ser5letKclass>7ni</ser5letKclass>
</ser5let>
<ser5letKmapping>
<ser5letKname>init1</ser5letKname>
<&rlKpattern>/regis</&rlKpattern>
</ser5letKmapping>
</weKapp>
OUTPUT:
&rasad '. &otluri (iddhartha %nstitute of Technolog! ./
&rasad '. &otluri (iddhartha %nstitute of Technolog! .1
&rasad '. &otluri (iddhartha %nstitute of Technolog! .3
&rasad '. &otluri (iddhartha %nstitute of Technolog! /4
RESULT:
Thus a table is created and the details are entered into the table using Bdbc from
the registration form successfull!.
&rasad '. &otluri (iddhartha %nstitute of Technolog! /)
Week-10 Date: 29-09-08
------------------------------------------------------------------------------------------------------------
AIM: #rite a =(& which does the following Bob
%nsert the details of the + or , users who register with the web site 7week36 b! using
registration form. Authenticate the user when he submits the login form using the user
name and password from the database 7similar to week1 instead of cookies6.
DESCRIPTION:
1SP Scripting Elements
=(& scripting elements let !ou insert =aa code into the serlet that will be generated
from the current =(& page. There are three forms:
). 98pressions of the form '() ex!ress"on (+ that are ealuated and inserted into
the output,
*. (criptlets of the form '( code (+ that are inserted into the serlet@s serv"ce
method, and
+. Declarations of the form '(, code (+ that are inserted into the bod! of the
serlet class, outside of an! e8isting methods.
9ach of these is described in more detail below.
1SP Expressions
A =(& e"pression is used to insert =aa alues directl! into the output. %t has the
following form:
< =aa 98pression >
The =aa e8pression is ealuated, conerted to a string, and inserted in the page. This
ealuation is performed at run:time 7when the page is requested6, and thus has full access
to information about the request. "or e8ample, the following shows the dateDtime that the
page was requested:
0urrent time: VbC new Baa.util.Date76 bT
To simplif! these e8pressions, there are a number of predefined ariables that !ou can
use. These implicit obBects are discussed in more detail later, but for the purpose of
e8pressions, the most important ones are:
&rasad '. &otluri (iddhartha %nstitute of Technolog! /*
re-uest, the Htt!Servlet.e-uestF
res!onse, the Htt!Servlet.es!onseF
sess"on, the Htt!Sess"on associated with the request 7if an!6F and
out, the Pr"nt/r"ter 7a buffered ersion of t!pe Js!/r"ter6 used to send output
to the client.
1SP Scriptlets
%f !ou want to do something more comple8 than insert a simple e8pression, =(&
scriptlets let !ou insert arbitrar! code into the serlet method that will be built to generate
the page. (criptlets hae the following form:
< =aa 0ode >
(criptlets hae access to the same automaticall! defined ariables as e8pressions.
(o, for e8ample, if !ou want output to appear in the resultant page, !ou would use the
out ariable.
Vb
(tring quer!Data C request.getauer!(tring76F
out.println7KAttached Y9T data: K ] quer!Data6F
bT
2ote that code inside a scriptlet gets inserted e"actly as written, and an! static
HT?L 7template te8t6 before or after a scriptlet gets conerted to print statements. This
means that scriptlets need not contain complete =aa statements, and blocks left open can
affect the static HT?L outside of the scriptlets.
1SP Declarations
A =(& declaration lets !ou define methods or fields that get inserted into the main
bod! of the serlet class 7outside of the serv"ce method processing the request6. %t has
the following form:
<! =aa 0ode >
(ince declarations do not generate an! output, the! are normall! used in
conBunction with =(& e8pressions or scriptlets. "or e8ample, here is a =(& fragment that
prints out the number of times the current page has been requested since the serer
booted 7or the serlet class was changed and reloaded6:
VbU priate int access0ount C 4F bT
&rasad '. &otluri (iddhartha %nstitute of Technolog! /+
PROGRAM:
Login.html:
<\KK3ome.htmlKK>
<html> <od!>
<center><h1>@X] "ompan! <td.</h1></center>
<tale order="1" width="100%" height="100%">
<tr>
<td 5align="top" align="center"><r/>
<form action="a&th.-sp"><tale>
<tr>
<td colspan="2" align="center"><><ogin +age</></td>
</tr>
<tr>
<td colspan="2" align="center"><>0nsp1</td>
</tr>
<tr>
<td>)ser Same</td>
<td><inp&t t!pe="te8t" name="&ser"/></td>
</tr>
<tr>
<td>+assword</td>
<td><inp&t t!pe="password" name="pwd"/></td>
</tr>
<tr>
<td>0nsp1</td>
<td>0nsp1</td>
</tr>
<tr>
<td colspan="2" align="center"><inp&t t!pe="s&mit" 5al&e="<og7S"/></td>
</tr>
</tale>
&rasad '. &otluri (iddhartha %nstitute of Technolog! /,
</form>
</td>
</tr>
</tale>
</od!>
</html>
Auth.jsp:
<%Zpage import="-a5a.sCl.*1"%>
<html>
<head>
<title>
6his is simple data ase e8ample in B'+</title>
</title>
</head>
<od! gcolor="!ellow">
<%\'tring &name,pwd1%>
<%
&name=reC&est.get+arameterL"&ser"M1
pwd=reC&est.get+arameterL"pwd"M1
tr!
I
"lass.forSameL"oracle.-dc.dri5er..racle%ri5er"M1
"onnection
con=%ri5er*anager.get"onnectionL"-dc#oracle#thin#Z1G9.100.101.19E#1921#""<(>","scott","tiger
"M1
'tatement st=con.create'tatementLM1
Nes&lt'et rs=st.e8ec&te[&er!L"select name,password from personal where name=="V&nameV"=
and password=="VpwdV"="M1
ifLrs.ne8tLMM
I
o&t.printlnL"(&thori;ed person"M1
&rasad '. &otluri (iddhartha %nstitute of Technolog! /-
J
else
I
o&t.printlnL")n(&thori;ed person"M1
J
con.closeLM1
J
catchL48ception eMIo&t.printlnL""VeM1J
%>
</od!>
</html>
OUTPUT:
&rasad '. &otluri (iddhartha %nstitute of Technolog! /.
RESULT:
The user is authenticated when he submits the login form using the user name and
password from the database.
&rasad '. &otluri (iddhartha %nstitute of Technolog! //
Week-11: Date: 06-10-08
------------------------------------------------------------------------------------------------------------
AIM: 98tract data from the tables and displa! them in the catalogue page using =D$0.
DESCRIPTION:
0reate tables in the database which contain the details of items 7books in our case
like $ook name, &rice, auantit!, Amount66 of each categor!. ?odif! !our catalogue page
7week *6 in such a wa! that !ou should connect to the database and e8tract data from the
tables and displa! them in the catalogue page using =D$0.
PROGRAM:
Retrieve.java:
import -a5a8.ser5let.*1
import -a5a8.ser5let.http.*1
import -a5a.sCl.*1
import -a5a.io.*1
import -a5a.&til.*1
p&lic class Netrie5e e8tends 3ttp'er5let
I
p&lic 5oid ser5iceL3ttp'er5letNeC&est reC,3ttp'er5letNesponse resM throws
'er5let48ception,7.48ception
I
res.set"ontent6!peL"te8t/html"M1
+rint,riter o&t=res.get,riterLM1
tr!I
"lass.forSameL"oracle.-dc.dri5er..racle%ri5er"M1
"onnection
con=%ri5er*anager.get"onnectionL"-dc#oracle#thin#Z1G9.100.101.19E#1921#ccla","scott","tiger"M1
'tatement s=con.create'tatementLM1
Nes&lt'et r=s.e8ec&te[&er!L"select * from cart"M1
o&t.printlnL"<center> <tale order=1>"M1
&rasad '. &otluri (iddhartha %nstitute of Technolog! /1
o&t.printlnL"<thead> <th> >oo/ name </th> <th> +rice </th> <th> [&antit! </th> <th> (mo&nt </th>
</thead>"M1
whileLr.ne8tLMM
I
o&t.printlnL"<tr> <td> "Vr.get'tringL1MV"</td> "M1
o&t.printlnL"<td> "Vr.get'tringL2MV"</td> "M1
o&t.printlnL"<td> "Vr.get7ntL3MV"</td> "M1
o&t.printlnL"<td> "Vr.get'tringL?MV"</td> </tr>"M1
J
o&t.printlnL"</tale></center>"M1
con.closeLM1
J
catchL'[<48ception sCM
I
o&t.printlnL"sCl e8ception"VsCM1
J
catchL"lassSotPo&nd48ception clM
I
o&t.printlnL"class not fo&nd"VclM1
J
J
J
web.xml:
<weKapp>
<ser5let>
<ser5letKname>set</ser5letKname>
<ser5letKclass>"artenter</ser5letKclass>
</ser5let>
<ser5let>
&rasad '. &otluri (iddhartha %nstitute of Technolog! /3
<ser5letKname>displa!</ser5letKname>
<ser5letKclass>Netrie5e</ser5letKclass>
</ser5let>
<ser5letKmapping>
<ser5letKname>set</ser5letKname>
<&rlKpattern>/enterdata</&rlKpattern>
</ser5letKmapping>
<ser5letKmapping>
<ser5letKname>displa!</ser5letKname>
<&rlKpattern>/displa!1</&rlKpattern>
</ser5letKmapping>
</weKapp>
&rasad '. &otluri (iddhartha %nstitute of Technolog! 14
CREATE THE TABLE AND INSERT VALUES INTO THE TABLE:
&rasad '. &otluri (iddhartha %nstitute of Technolog! 1)
OUTPUT:
RESULT:
The data is e8tracted from the tables and displa!ed in the catalogue page using =D$0
&rasad '. &otluri (iddhartha %nstitute of Technolog! 1*
Week-12: Date: 18-10-08
------------------------------------------------------------------------------------------------------------
AIM: ?odif! cart =(&page to achiee the d!namism with the HTT& protocol and session
management
DESCRIPTION:
HTTP is a stateless protocol. (ession is required to maintain the state.
Methods of session Object:
There are numerous methods aailable for session >bBect. (ome are:
#etAttr"bute%Str"n# nae&
#etAttr"bute0aes
"s0e1%&
#etCreat"onT"e
#et2d
"nval"date%&
#etLastAccessedT"e
#etMax2nact"ve2nterval
reoveAttr"bute%Str"n# nae&
setAttr"bute%Str"n#3 object&
The VBsp:includeT element allows !ou to include either static and d!namic files in a =(&
file.
Program :
Cart .java
import java.util.`;
import javax.servlet.http.`;
import javax.servlet.`;
import java.io.`;
public class Cart extends HttpServlet

&rasad '. &otluri (iddhartha %nstitute of Technolog! 1+


public void init(ServletConfig config) throws
ServletException

super.init(config);
]
public void service(HttpServletRequest
req,HttpServletResponse res) throws
IOException,ServletException

res.setContentType("text/html");
PrintWriter pwres.getWriter();
HttpSession hsreq.getSession();
ArrayList cart(ArrayList)hs.getAttribute("cart");
if(cartnull)

pw.println("No items in your cart");


cartnew ArrayList();
hs.setAttribute("cart",cart);
]
String itemselected];
String item;
itemselectedreq.getParameterValues("book");
if(itemselected!null)

for(int i0;i<itemselected.length;i++)

itemitemselectedi];
cart.add(item);

]]
pw.println("Items in the cart<br>");
Iterator itcart.iterator();
&rasad '. &otluri (iddhartha %nstitute of Technolog! 1,
while(it.hasNext())

pw.println("<br><b>"+it.next()+"</b>");
]
]
]
Catalogue.java
import java.util.`;
import javax.servlet.http.`;
import javax.servlet.`;
import java.io.`;
public class Catalogue extends HttpServlet

int itemcount0;
public void init(ServletConfig config) throws
ServletException

super.init(config);
]
public void service(HttpServletRequest
req,HttpServletResponse res) throws
IOException,ServletException

res.setContentType("text/html");
PrintWriter pwres.getWriter();
HttpSession hsreq.getSession();
ArrayList cart(ArrayList)hs.getAttribute("cart");
if(cart!null)

itemcountcart.size();
&rasad '. &otluri (iddhartha %nstitute of Technolog! 1-
]
pw.println("You have"+itemcount+"items in cart");

pw.println("<body><center><fieldset><legend>Catalogue</leg
end><form action'cart' method'get'><input
type'checkbox' value'1ava2'
name'book'>java2</input><br>");
pw.println("<input type'checkbox' name'book'
value'web programming'>Web
programming</input><br>");
pw.println("<input type'checkbox' name'book'
value'1ava2 Complete Reference'>1ava2 Complete
Reference</input><br>");
pw.println("<input type'checkbox' name'book'
value'Internet & World wide web'>Internet & World wide
web</input><br>");
pw.println("<input type'checkbox' name'book'
value'Core servlets &1SP'>Core servlets
&1SP</input><br>");
pw.println("<input type'checkbox' name'book'
value'12EE 3rd edition'>12EE 3rd edition</input><br>");
pw.println("<input type'checkbox' name'book'
value'Electronic Devices and circuits'>Electronic Devices and
circuits</input><br>");
pw.println("<input type'checkbox' name'book'
value'Software Engineering'>Software
Engineering</input><br>");
pw.println("<input type'checkbox' name'book'
value'software project management'>software project
management</input><br>");
&rasad '. &otluri (iddhartha %nstitute of Technolog! 1.
pw.println("<input type'checkbox' name'book'
value'Computer networks'>Computer
networks</input><br>");
pw.println("</fieldset></center>");
pw.println("<input type'submit' value'submit'>");

]
]
<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>
&rasad '. &otluri (iddhartha %nstitute of Technolog! 1/
<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>
<servlet-class>Cart</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>cart</servlet-name>
<url-pattern>/cart</url-pattern>
</servlet-mapping>
</web-app>
&rasad '. &otluri (iddhartha %nstitute of Technolog! 11
Result : Thus the session management is successfull! created using Bsp
Week 13:
Aim : Write a program to implement MVC architecture.
Description :
&rasad '. &otluri (iddhartha %nstitute of Technolog! 13
Model-View-Controller Pattern
?odel:'iew:0ontroller 7?'06 is a classic design pattern often used b! applications
that need the abilit! to maintain multiple iews of the same data. The ?'0 pattern
hinges on a clean separation of obBects into one of three categories c models for
maintaining data, iews for displa!ing all or a portion of the data, and controllers for
handling eents that affect the model or iew7s6.
$ecause of this separation, multiple iews and controllers can interface with the same
model. 9en new t!pes of iews and controllers that neer e8isted before can interface
with a model without forcing a change in the model design.
How It Works
The ?'0 abstraction can be graphicall! represented as follows.
9ents t!picall! cause a controller to change a model, or iew, or both. #heneer a
controller changes a modelAs data or properties, all dependent iews are automaticall!
updated. (imilarl!, wheneer a controller changes a iew, for e8ample, b! reealing
areas that were preiousl! hidden, the iew gets data from the underl!ing model to
refresh itself.
A Concrete Example
#e e8plain the ?'0 pattern with the help of a simple spinner component which
consists of a te8t field and two arrow buttons that can be used to increment or decrement
a numeric alue shown in the te8t field. #e currentl! do not hae an element t!pe that
can directl! represent a spinner component, but it eas! is to s!nthesiMe a spinner using
e8isting element t!pes.
&rasad '. &otluri (iddhartha %nstitute of Technolog! 34
The spinnerAs data is held in a model that is shared with the te8t field. The te8t field
proides a view of the spinnerAs current alue. 9ach button in the spinner is an event
source, that spawns an action event eer! time it is clicked. The buttons can be hooked
up to trampolines that receie action eents, and route them to an action listener that
eentuall! handles that eent. Recall that a trampoline is a predefined action listener that
simpl! delegates action handling to another listener.
Depending on the source of the eent, the ultimate action listener either increments or
decrements the alue held in the model c The action listener is an e8ample of a
controller.
The trampolines that initiall! receie the action eents fired b! the arrow buttons, are
also controllers c Howeer, instead of modif!ing the spinnerAs model directl!, the!
delegate the task to a separate controller 7action listener6.
Multiple Controllers
The ?'0 pattern allows an! number of controllers to modif! the same model. #hile
we hae so far focused onl! on the two arrow buttons as likel! source of eents, there is,
in fact, a third eent source in this e8ample c #heneer the te8t field has focus, hitting
the enter ke! fires off an action eent that ma! potentiall! be handled b! a different
action listener than the one handling action eents from the buttons.
&rogram :
&rasad '. &otluri (iddhartha %nstitute of Technolog! 3)
Eshop.jsp:
<%Z page session="tr&e" %>
<html>
<head>
<title>>..H '6.N4</title>
</head>
<od! gcolor="Y33""PP">
<font face="6imes Sew Noman,6imes" si;e="V3">
>..H '6.N4
</font>
<hr><p>
<center>
<form name="shoppingPorm"
action="'hopping'er5let"
method="+.'6">
<>>..H#</>
<select name=>..H>
<option> 109EE W 3ans >ergsten W Ba5a 'er5er +ages W .=Neill! W 2 W 3?.G9</option>
<option> 109EG W %eitel W 7nternet W*cRraw 3ill W ? W ??.G9</option>
<option> 109G0 W ,inston W @*< >7><4 W,ile! W 2 W 1?.G9</option>
</select>
<>[&antit!# </><inp&t t!pe="te8t" name="Ct!" '7]4="3" 5al&e=1>
<inp&t t!pe="hidden" name="action" 5al&e="(%%">
<inp&t t!pe="s&mit" name="'&mit" 5al&e="(dd to "art">
</form>
</center>
<p>
<-sp#incl&de page=""art.-sp" fl&sh="tr&e" />
</od!>
</html>
&rasad '. &otluri (iddhartha %nstitute of Technolog! 3*
0art.Bsp:
<%Z page session="tr&e" import="-a5a.&til.*, shopping.>..H" %>
<%
Oector &!list = LOectorM session.getOal&eL"shopping.shoppingcart"M1
if L&!list \= n&ll 00 L&!list.si;eLM > 0MM I
%>
<center>
<tale order="0" cellpadding="0" width="100%" gcolor="YPPPPPP">
<tr>
<td><>7'>S</></td>
<td><>()63.N</></td>
<td><>676<4</></td>
<td><>+)><7'34N</></td>
<td><>4%767.S</></td>
<td><>+N7"4</></td>
<td><>[)(S676X</></td>
<td></td>
</tr>
<%
for Lint inde8=01 inde8 < &!list.si;eLM1inde8VVM I
>..H an.rder = L>..HM &!list.element(tLinde8M1
%>
<tr>
<td><><%= an.rder.getisnLM %></></td>
<td><><%= an.rder.get(&thorLM %></></td>
<td><><%= an.rder.get6itleLM %></></td>
<td><><%= an.rder.get+&lisherLM %></></td>
<td><><%= an.rder.get4ditionLM %></></td>
<td><><%= an.rder.get+riceLM %></></td>
<td><><%= an.rder.get[&antit!LM %></></td>
<td>
&rasad '. &otluri (iddhartha %nstitute of Technolog! 3+
<form name="deletePorm"
action="'hopping'er5let"
method="+.'6">
<inp&t t!pe="s&mit" 5al&e="%elete">
<inp&t t!pe="hidden" name= "delinde8" 5al&e==<%= inde8 %>=>
<inp&t t!pe="hidden" name="action" 5al&e="%4<464">
</form>
</td>
</tr>
<% J %>
</tale>
<p>
<form name="chec/o&tPorm"
action="'hopping'er5let"
method="+.'6">
<inp&t t!pe="hidden" name="action" 5al&e=""34"H.)6">
<inp&t t!pe="s&mit" name=""hec/o&t" 5al&e=""hec/o&t">
</form>
</center>
<% J %>
Checkout.jsp:
<%Z page session="tr&e" import="-a5a.&til.*, shopping.>..H" %>
<html>
<head>
<title>>..H '6.N4</title>
</head>
<od! gcolor="Y33""PP">
<font face="6imes Sew Noman,6imes" si;e=V3>
>..H '6.N4 "34"H .)6
</font>
<hr><p>
&rasad '. &otluri (iddhartha %nstitute of Technolog! 3,
<center>
<tale order="0" cellpadding="0" width="100%" gcolor="YPPPPPP">
<tr>
<td><>7'>S</></td>
<td><>()63.N</></td>
<td><>676<4</></td>
<td><>+)><7'34N</></td>
<td><>4%767.S</></td>
<td><>+N7"4</></td>
<td><>[)(S676X</></td>
<td></td>
</tr>
<%
Oector &!list = LOectorM session.getOal&eL"shopping.shoppingcart"M1
'tring amo&nt = L'tringM reC&est.get(ttri&teL"amo&nt"M1
for Lint i=01 i < &!list.si;eLM1iVVM I
>..H an.rder = L>..HM &!list.element(tLiM1
%>
<tr>
<td><><%= an.rder.getisnLM %></></td>
<td><><%= an.rder.get(&thorLM %></></td>
<td><><%= an.rder.get6itleLM %></></td>
<td><><%= an.rder.get+&lisherLM %></></td>
<td><><%= an.rder.get4ditionLM %></></td>
<td><><%= an.rder.get+riceLM %></></td>
<td><><%= an.rder.get[&antit!LM %></></td>
</tr>
<%
J
session.in5alidateLM1
%>
&rasad '. &otluri (iddhartha %nstitute of Technolog! 3-
<tr>
<td> </td>
<td> </td>
<td><>6.6(<</></td>
<td><>A<%= amo&nt %></></td>
<td> </td>
</tr>
</tale>
<p>
<a href="4shop.-sp">'hop some more\</a>
</center>
</od!>
</html>
Error.html:
<html>
<od!>
<h1>
'orr!, there was an &nreco5erale error\ <r>
+lease tr! <a href="/e8amples/-sp/shopping/4'hop.-sp">again</a>.
</h1>
</od!>
</html>
OUTPUT:
&rasad '. &otluri (iddhartha %nstitute of Technolog! 3.
Web.xml:
<weKapp>
<ser5let>
<ser5letKname>'hopping'er5let</ser5letKname>
<ser5letKclass>'hopping'er5let</ser5letKclass>
</ser5let>
<ser5letKmapping>
<ser5letKname>'hopping'er5let</ser5letKname>
<&rlKpattern>/'hopping'er5let</&rlKpattern>
</ser5letKmapping>
</weKapp>
ShoppingServlet.java:
import -a5a.&til.*1
import -a5a.io.*1
import -a5a8.ser5let.*1
import -a5a8.ser5let.http.*1
import shopping.>..H1
&rasad '. &otluri (iddhartha %nstitute of Technolog! 3/
p&lic class 'hopping'er5let e8tends 3ttp'er5let I
p&lic 5oid initL'er5let"onfig confM throws 'er5let48ception I
s&per.initLconfM1
J
p&lic 5oid do+ost L3ttp'er5letNeC&est reC, 3ttp'er5letNesponse resM
throws 'er5let48ception, 7.48ception I
3ttp'ession session = reC.get'essionLfalseM1
if Lsession == n&llM I
res.sendNedirectL"/error.html"M1
J
Oector &!list=LOectorMsession.getOal&eL"shopping.shoppingcart"M1
'tring action = reC.get+arameterL"action"M1
if L\action.eC&alsL""34"H.)6"MM I
if Laction.eC&alsL"%4<464"MM I
'tring del = reC.get+arameterL"delinde8"M1
int d = Lnew 7ntegerLdelMM.intOal&eLM1
&!list.remo5e4lement(tLdM1
J else if Laction.eC&alsL"(%%"MM I
oolean match=false1
>..H a"% = get>..HLreCM1
if L&!list==n&llM I
&!list = new OectorLM1 //first order
&!list.add4lementLa"%M1
J else I // not first &!
for Lint i=01 i< &!list.si;eLM1 iVVM I
>..H cd = L>..HM &!list.element(tLiM1
if Lcd.get6itleLM.eC&alsLa"%.get6itleLMMM I
cd.set[&antit!Lcd.get[&antit!LMVa"%.get[&antit!LMM1
&!list.set4lement(tLcd,iM1
match = tr&e1
&rasad '. &otluri (iddhartha %nstitute of Technolog! 31
J //end of if name matches
J // end of for
if L\matchM
&!list.add4lementLa"%M1
J
J
session.p&tOal&eL"shopping.shoppingcart", &!listM1
'tring &rl="/4shop.-sp"1
// 'er5let"onte8t sc = get'er5let"onte8tLM1
NeC&est%ispatcher rd = reC.getNeC&est%ispatcherL&rlM1
rd.forwardLreC, resM1
J
else if Laction.eC&alsL""34"H.)6"MM I
float total =01
for Lint i=01 i< &!list.si;eLM1iVVM I
>..H an.rder = L>..HM &!list.element(tLiM1
float price= an.rder.get+riceLM1
int Ct! = an.rder.get[&antit!LM1
total V= Lprice * Ct!M1
J
total V= 0.0091
'tring amo&nt = new PloatLtotalM.to'tringLM1
int n = amo&nt.inde8.fL=.=M1
amo&nt = amo&nt.s&stringL0,nV3M1
reC.set(ttri&teL"amo&nt",amo&ntM1
'tring &rl="/"hec/o&t.-sp"1
'er5let"onte8t sc = get'er5let"onte8tLM1
NeC&est%ispatcher rd = sc.getNeC&est%ispatcherL&rlM1
rd.forwardLreC,resM1
J
J
&rasad '. &otluri (iddhartha %nstitute of Technolog! 33
pri5ate >..H get>..HL3ttp'er5letNeC&est reCM I

'tring m!>..H = reC.get+arameterL">..H"M1
'tring Ct! = reC.get+arameterL"Ct!"M1
'tring6o/eni;er t = new 'tring6o/eni;erLm!>..H,"W"M1
'tring isn= t.ne8t6o/enLM1
'tring a&thor= t.ne8t6o/enLM1
'tring title = t.ne8t6o/enLM1
'tring p&lisher = t.ne8t6o/enLM1
'tring 4dition = t.ne8t6o/enLM1
'tring price = t.ne8t6o/enLM1
price = price.replaceL=A=,= =M.trimLM1
>..H oo/ = new >..HLM1
oo/.setisnLisnM1
oo/.set(&thorLa&thorM1
oo/.set6itleLtitleM1
oo/.set+&lisherLp&lisherM1
oo/.set4ditionL4ditionM1
oo/.set+riceLLnew PloatLpriceMM.floatOal&eLMM1
oo/.set[&antit!LLnew 7ntegerLCt!MM.intOal&eLMM1
ret&rn oo/1
J
J
book.java:
pac/age shopping1
p&lic class >..H I
'tring isn1
'tring a&thor1
'tring title1
'tring p&lisher1
'tring 4dition1
&rasad '. &otluri (iddhartha %nstitute of Technolog! )44
float price1
int C&antit!1
p&lic >..HLM I
isn=""1
a&thor=""1
title=""1
p&lisher=""1
4dition=""1
price=01
C&antit!=01
J
p&lic 5oid set+&lisherL'tring title1M I
p&lisher=title11
J
p&lic 'tring get+&lisherLM I
ret&rn p&lisher1
J
p&lic 5oid set4ditionL'tring gro&p1M I
4dition=gro&p11
J
p&lic 'tring get4ditionLM I
ret&rn 4dition1
J
p&lic 5oid setisnL'tring titleM I
isn=title1
J
p&lic 'tring getisnLM I
ret&rn isn1
J
p&lic 5oid set(&thorL'tring gro&pM I
a&thor=gro&p1
&rasad '. &otluri (iddhartha %nstitute of Technolog! )4)
J
p&lic 'tring get(&thorLM I
ret&rn a&thor1
J
p&lic 5oid set6itleL'tring ct!M I
title=ct!1
J
p&lic 'tring get6itleLM I
ret&rn title1
J
p&lic 5oid set+riceLfloat pM I
price=p1
J
p&lic float get+riceLM I
ret&rn price1
J
p&lic 5oid set[&antit!Lint CM I
C&antit!=C1
J
p&lic int get[&antit!LM I
ret&rn C&antit!1
J
J
>WT&WT:
&rasad '. &otluri (iddhartha %nstitute of Technolog! )4*
&rasad '. &otluri (iddhartha %nstitute of Technolog! )4+
R9(WLT: Thus the cart page is d!namited with HTT& sessions and use$ean concept.
Experiment :14
Aim : Write a program to implement custom tag libraries in 1SP
Description :
Program :
First.jsp
< taglib uri"hello" prefix"examples">
<html>
<head>
&rasad '. &otluri (iddhartha %nstitute of Technolog! )4,
<title>First Custom tags</title>
</head>
<body>
<i><examples:hello/>
</i>
</body>
</html>
Web.xml
<web-app>
<taglib>
<taglib-uri>hello</taglib-uri>
<taglib-location>/WEB-INF/tlds/hello.tld</taglib-location>
</taglib>
</web-app>
Create a folder called tlds in WEB-INF directory.
Hello.tld
<taglib>
<tlib-version>1.0</tlib-version>
<jsp-version>1.2</jsp-version>
<tag>
<name>hello</name>
<tag-class>tagext.HelloTag</tag-class>
<body-content>1SP</body-content>
</tag>
</taglib>
&rasad '. &otluri (iddhartha %nstitute of Technolog! )4-
HelloTag.java
package tagext;
import javax.servlet.jsp.`;
import javax.servlet.jsp.tagext.TagSupport;
import java.util.`;
public class HelloTag extends TagSupport

public int doStartTag()

return EVAL_BODY_INCLUDE;
]
public int doEndTag()

Date datenew Date();


try

pageContext.getOut().write("HellOWorld");
pageContext.getOut().write("My name is :"+getClass().getName()+"and
it's"+date);
]catch(Exception e)]
return EVAL_PAGE;
]
]
Output
&rasad '. &otluri (iddhartha %nstitute of Technolog! )4.
Result :
Thus the implementation of custom tag libraries in 1SP is done.
Experiment No : 14
Aim : Display Hello World using Struts Framework in
NetBeans.
Desription:
Apache (truts * is an elegant, e8tensible framework for creating enterprise:read! =aa
web applications. The framework is designed to streamline the full deelopment c!cle,
from building, to deplo!ing, to maintaining applications oer time.
&rasad '. &otluri (iddhartha %nstitute of Technolog! )4/
Apache (truts * was originall! known as #eb#ork *. After working independentl! for
seeral !ears, the #eb#ork and (truts communities Boined forces to create (truts
*
. This
new ersion of (truts is simpler to use and closer to how (truts was alwa!s meant to be.
Implementation:
(tep ):
(tep *:
&rasad '. &otluri (iddhartha %nstitute of Technolog! )41
(tep +:
(tep ,:
&rasad '. &otluri (iddhartha %nstitute of Technolog! )43
step -:
&rasad '. &otluri (iddhartha %nstitute of Technolog! ))4
step .:
step /:

&rasad '. &otluri (iddhartha %nstitute of Technolog! )))
step 1:
step 3:
&rasad '. &otluri (iddhartha %nstitute of Technolog! ))*
auestion S Answers
Q: After I have edited an HTML fle, I cannot view the result in my browser.
Why?
A: Make sure that you have saved the fle with a proper name and extension like
"c:\mypage.htm". Also make sure that you use the same name when you open
the fle in your browser.
Q: I have edited an HTML fle, but the changes don't show in the browser.
Why?
A: A browser caches pages so it doesn't have to read the same page twice. When
you have modifed a page, the browser doesn't know that. Use the browser's
refresh/reload button to force the browser to reload the page.
Q: What browser should I use?
A: You can do all the training with all of the well-known browsers, like Internet
Explorer, Firefox, Netscape, or Opera. However, some of the examples in our
advanced classes require the latest versions of the browsers.
Q: Does my computer have to run Windows? What about a Mac?
A: You can do all your training on a non-Windows computer like a Mac.
). #hat is X?L\
7ans6 X?L is the 98tensible ?arkup Language. %t improes the functionalit! of the #eb
b! letting !ou identif! !our information in a more accurate, fle8ible, and adaptable wa!.
%t is e8tensible because it is not a fi8ed format like HT?L 7which is a single, predefined
!ar"up la#guage6. %nstead, X?L is actuall! a !etala#guageca language for describing
other languagescwhich lets !ou design !our own markup languages for limitless
different t!pes of documents. X?L can do this because it@s written in (Y?L, the
international standard metalanguage for te8t document markup 7%(> 11/36.
2.#hat is a markup language\
7ans6 A markup language is a set of words and s!mbols for describing the identit! of
pieces of a document 7for e8ample dthis is a paragraphA, dthis is a headingA, dthis is a listA,
dthis is the caption of this figureA, etc6. &rograms can use this with a st!lesheet to create
output for screen, print, audio, ideo, $raille, etc.
(ome markup languages 7eg those used in wordprocessors6 onl! describe appearances
&rasad '. &otluri (iddhartha %nstitute of Technolog! ))+
7dthis is italicsA, dthis is boldA6, but this method can onl! be used for displa!, and is not
normall! re:usable for an!thing else.
X?L is sometimes referred to as dself:describing dataA because the names of the markup
elements should represent the t!pe of content the! hold.
+. #hat is X?L for 7aka d#here should % use X?LA6\
7ans6 %ts goal is to enable generic (Y?L to be sered, receied, and processed on
the #eb in the wa! that is now possible with HT?L. X?L has been designed for
ease of implementation and for interoperabilit! with both (Y?L and HT?L.
(ee#here.s the spec/
Despite earl! attempts, browsers neer allowed other (Y?L, onl! HT?L 7although there
were unknownplugins6, and the! allowed it 7een encouraged it6 to be corrupted or
broken, which held deelopment back for oer a decade b! making it impossible to
program for it reliabl!. X?L fi8es that b! making it compulsor! to stick to the rules, and
b! making the rules much simpler than (Y?L.
$ut X?L is not Bust for #eb pages: in fact it@s er! rarel! used for #eb pages on its own
because browsers still don@t proide reliable support for formatting and transforming it.
0ommon uses for X?L include:
%nformation identification
because !ou can define !our own markup, !ou can define meaningful names for all
!our information items.
%nformation storage
because X?L is portable and non:proprietar!, it can be used to store te8tual
information across an! platform. $ecause it is backed b! an international standard, it
will remain accessible and processable as a data format.
%nformation structure
X?L can therefore be used to store and identif! an! kind of 7hierarchical6
information structure, especiall! for long, deep, or comple8 document sets or data
sources, making it ideal for an information:management back:end to sering the #eb.
0his is its most common #eb application, with a transformation s!stem to sere it as
HT?L until such time as browsers are able to handle X?L consistentl!.
&ublishing
The original goal of X?L as defined in the quotation at the start of this section.
0ombining the three preious topics 7identit!, storage, structure6 means it is possible
to get all the benefits of robust document management and control 7with X?L6 and
publish to the #eb 7as HT?L6 as well as to paper 7as &D"6 and to other formats 7eg
$raille, Audio, etc6 from a single source document b! using the appropriate
st!lesheets.
?essaging and data transfer
X?L is also er! heail! used for enclosing or encapsulating information in order to
&rasad '. &otluri (iddhartha %nstitute of Technolog! )),
pass it between different computing s!stems which would otherwise be unable to
communicate. $! proiding a lingua franca for data identit! and structure, it proides
a common enelope for inter:process communication 7messaging6.
#eb serices
$uilding on all of these, as well as its use in browsers, machine:processable data can
be e8changed between consenting s!stems, where before it was onl! comprehensible
b! humans 7HT?L6. #eather serices, e:commerce sites, blog newsfeeds, A=aX
sites, and thousands of other data:e8change serices use X?L for data management
and transmission, and the web browser for displa! and interaction.
,. #hat is (Y?L\
7ans6(Y?L is the (tandard YeneraliMed ?arkup Language 7%(> 11/3:)31.6, the
international standard for defining descriptions of the structure of different t!pes of
electronic document. There is an (Y?L "Aa from Daid ?egginson at
4tt!$55at46alban76edu$8899545s#l5cts-fa-64t
(Y?L is er! large, powerful, and comple8. %t has been in hea! industrial and
commercial use for nearl! two decades, and there is a significant bod! of e8pertise and
software to go with it.
X?L is a lightweight cut:down ersion of (Y?L which keeps enough of its functionalit!
to make it useful but remoes all the optional features which made (Y?L too comple8 to
program for in a #eb enironment.
-. #hat is HT?L\
7A2(6HT?L is the H!perTe8t ?arkup Language 7R"0 )1..6, which started as a small
application of question A.,, (Y?L for the #eb, originating with Tim $erners:Lee at
09R2 in )313;34.
%t defines a er! simple class of report:st!le documents, with section headings,
paragraphs, lists, tables, and illustrations, with a few informational elements, but er!
few presentational elements I)4J, plus some h!perte8t and multimedia. (ee the question
on e8tending HT?L. The current recommendation is to use the X?L ersion, XHT?L.
There is a HT?L and XHT?L "Aa maintained b! (teen &emberton at
4tt!$5511161:6or#5Mar;<!5=99>5x4tl-fa-
..Aren@t X?L, (Y?L, and HT?L all the same thing\
7ans6 2ot quiteF (Y?L is the mother tongue, and has been used for describing thousands
of different document t!pes in man! fields of human actiit!, from transcriptions of
ancient %rish manuscripts to the technical documentation for stealth bombers, and from
patients@ medical and clinical records to musical notation. (Y?L is er! large and
comple8, howeer, and probabl! oerkill for most common office desktop applications.
X?L is an abbreiated ersion of (Y?L, to make it easier to use oer the #eb, easier for
&rasad '. &otluri (iddhartha %nstitute of Technolog! ))-
!ou to define !our own document t!pes, and easier for programmers to write programs to
handle them. %t omits all the comple8 and less:used options of (Y?L in return for the
benefits of being easier to write applications for, easier to understand, and more suited to
delier! and interoperabilit! oer the #eb. $ut it is still (Y?L, and X?L files ma! still
be processed in the same wa! as an! other (Y?L file 7see the question on X?L
software6.
HT?L is Bust one of man! (Y?L or X?L applicationscthe one most frequentl! used
on the #eb.
Technical readers will find it more useful to think of X?L as being (Y?Lee rather than
HT?L]].
/.#ho is responsible for X?L\
7ans6 X?L is a proBect of the #orld #ide #eb 0onsortium 7#+06, and the deelopment
of the specification is superised b! an X?L #orking Yroup. A (pecial %nterest Yroup of
co:opted contributors and e8perts from arious fields contributed comments and reiews
b! email.
X?L is a public format: it is not a proprietar! deelopment of an! compan!, although the
membership of the #Y and the (%Y represented companies as well as research and
academic institutions. The ).4 specification was accepted b! the #+0 as a
Recommendation on "eb )4, )331.
1.#h! is X?L such an important deelopment\
7Ans6 %t remoes two constraints which were holding back #eb deelopments:
dependence on a single, infle8ible document t!pe 7HT?L6 which was being much
abused for tasks it was neer designed forF
the comple8it! of full question A.,, (Y?L, whose s!nta8 allows man! powerful but
hard:to:program options.
X?L allows the fle8ible deelopment of user:defined document t!pes. %t proides a
robust, non:proprietar!, persistent, and erifiable file format for the storage and
transmission of te8t and data both on and off the #ebF and it remoes the more comple8
options of (Y?L, making it easier to program for.
3.#h! not Bust carr! on e8tending HT?L\
7ans6 HT?L was alread! oerburdened with doMens of interesting but incompatible
inentions from different manufacturers, because it proides onl! one wa! of describing
!our information.
X?L allows groups of people or organiMations to question 0.)+, create their own
customiMed markup applications for e8changing information in their domain 7music,
chemistr!, electronics, hill:walking, finance, surfing, petroleum geolog!, linguistics,
cooking, knitting, stellar cartograph!, histor!, engineering, rabbit:keeping, question 0.)3,
mathematics, genealog!, etc6.
&rasad '. &otluri (iddhartha %nstitute of Technolog! )).
HT?L is now well be!ond the limit of its usefulness as a wa! of describing information,
and while it will continue to pla! an important role for the content it currentl! represents,
man! new applications require a more robust and fle8ible infrastructure.
)4.#h! should % use X?L\ 7aka d#hat is X?L for\6
7ans6 Here are a few reasons for using X?L 7in no particular order6. 2ot all of these will
appl! to !our own requirements, and !ou ma! hae additional reasons not mentioned
here 7if so, please let the editor of the "Aa knowU6.
X?L can be used to describe and identif! information accuratel! and
unambiguousl!, in a wa! that computers can be programmed to dunderstandA !our
information 7well, at least manipulate as if the! could understand it6.
X?L allows documents which are all the same t!pe to be created and handled
consistentl! and without structural errors, because it proides a standardised wa!
of describing, controlling, or allowingDdisallowing particular t!pes of document
structure. I2ote that this has absolutel! nothing whateer to do with formatting,
appearance, or the actual te8t or data content of !our documents, onl! the
structure of them. %f !ou want st!ling or formatting, see question 0.*,, dHow do %
control formatting and appearance\A.J
X?L proides a robust and durable format for information storage and
transmission. Robust because it is based on a proen standard, and can thus be
tested and erifiedF durable 7persistent6 because it uses plain:te8t file formats
which will outlast proprietar! binar! ones.
X?L proides a common s!nta8 for messaging s!stems for the e8change of
information between applications. &reiousl!, each messaging s!stem had its own
format and all were different, which made inter:s!stem messaging unnecessaril!
mess!, comple8, and e8pensie. %f eer!one uses the same s!nta8 it makes
writing these s!stems much faster and more reliable.
X?L is free. 2ot Bust free of charge 7free as in beer6 but free of legal
encumbrances 7free as in speech6. %t doesn@t belong to an!one, so it can@t be
hiBacked or pirated. And !ou don@t hae to pa! a fee to use it 7!ou can of course
choose to use commercial software to deal with it, for lots of good reasons, but
!ou don@t pa! for X?L itself6.
X?L information can be manipulated programmaticall! 7under machine control6,
so X?L documents can be pieced together from disparate sources, or taken apart
and re:used in different wa!s. The! can be conerted into an! other format with
no loss of information.
X?L lets !ou separate form 7appearance6 from content. Zour X?L file contains
!our document information 7te8t, data6 and identifies its structure: !our
formatting and other processing needs are identified separatel! in a st!lesheet or
processing s!stem. The two are combined at output time to appl! the required
formatting to the te8t or data identified b! its structure 7location, position, rank,
order, or whateer6.
&rasad '. &otluri (iddhartha %nstitute of Technolog! ))/
An! of the Design Yoals listed in the X?L (pecification.
)). #here do % find more information about X?L\
7ans6 >nline, there@s the X?L (pecification and the ancillar! documentation aailable
from the #+0F Robin 0oer@s (Y?LDX?L #eb pages with an e8tensie list of online
reference material and links to softwareF and a summar! and condensed "Aa"&R%'AT9
Yoogle or other search engine.
"or offline resources, see the lists of books, articles, and software for X?L in Robin
0oer@s (Y?L and X?L #eb pages. That site should alwa!s be !our first port of call.
The eents listed below are the ones % hae been told about. &lease mail me if !ou come
across others: there are man! other X?L eents around the world, and most of them are
announced on the mailing lists and newsgroups.
)*.#here can % discuss implementation and deelopment of X?L\
7Ans6 The two principal online support media are Wsenet newsgroups and mailing lists.
The %R0 network is also used to some e8tent, and most indiidual proBects and programs
hae their own topic:specific bulletin:boards on their web sites.
"or off:line support, see question A.)), d#here do % find more information about X?L\A
for details of conferences and summerschools.
The Wsenet newsgroups are comp.te8t.8ml and to a certain e8tent comp.te8t.sgml.
Ask !our %nternet &roider for access to these, or use a #eb interface like Yoogle
Yroups. %f !our browser or mailer doesn@t proide newsreading facilities, install
one that does, or 7better6 use a standalone newsreader.
The general:purpose mailing list for public discussion is X?L:L: to subscribe,
isit the #eb site and click on the link to Boin.
"or those deeloping software components for X?L there is the 8ml:de mailing
list. Zou can subscribe b! sending a );line mail message to xl-dev-
re-uest?l"sts6xl6or# sa!ing Bust S<@SC.2@E. 2ote that this list is for those
people actiel! inoled in deeloping resources for X?L. %t is not for general
information about X?L 7use the X?L:L list aboe for that6.
The X(L:List is for for discussing X(L 7both X(LT and X(L:">6. "or details of
how to subscribe, see 4tt!$551116ulberr7tec46co5xsl5xsl-l"st.
)+. #hat is the difference between X?L and 0 or 0]] or =aa\
7ans6 0 and 0]] 7and other languages like ">RTRA2, or &ascal, or 'isual $asic, or =aa
or hundreds more6 are programming languages with which !ou specif! calculations,
actions, and decisions to be carried out in order:
od curconf"#A"f left%date3B& ) C9D-A!rC3
t6!ut CA!r"l Eool,C3
f6!ut da7s%F:DD9=99GF3FDDMMHHHHF& -
&rasad '. &otluri (iddhartha %nstitute of Technolog! ))1
da7s%sdate3FDDMMHHHHF&
C ore s4o!!"n# da7s to Sa4a"nCIJ

X?L is a markup specification language with which !ou can design wa!s of describing
information 7te8t or data6, usuall! for storage, transmission, or processing b! a program.
%t sa!s nothing about what !ou should do with the data 7although !our choice of element
names ma! hint at what the! are for6:
'!art nu)CDA>=C odels)CLS A. DE HK LJC
u!date)C=99D-DD-==C+
'nae+Cas4aft end bear"n# retent"on c"rcl"!'5nae+
'"a#e dra1"n#)C..M8-d4:NC t7!e)CSVKC x)C>NBC
7)C==BC5+
'a;er "d)C.ONN8C+."n#to1n Easteners Ltd'5a;er+
'notes+An#le-nosed "nsert"on tool 'tool
"d)CKH=GC5+ "s re-u"red for t4e reoval
and re!laceent of t4"s !art6'5notes+
'5!art+

>n its own, an (Y?L or X?L file 7including HT?L6 doesn@t do an!thing. %t@s a data
format which Bust sits there until !ou run a program which does something (ith it. (ee
also the question about how to run or e8ecute X?L files.
: Are sessions created on the server side?
A: A serlet session is created and stored on the serer side. The serlet container
keeps track of all the sessions it manages and fulfils serlet A&% requests to get
Htt!Sess"ons, manipulate obBect data stored with them and trigger eent
callbacks.
To the maintain the session, #eb clients must pass back a alid session identifier
as a cookie header alue or d!namicall! generated WRL parameter. %n this sense,
the session is also stored b! the client, but onl! as a token reference.
Q: Can I create a session with GenericServlet?
&rasad '. &otluri (iddhartha %nstitute of Technolog! ))3
A: There are no protocol:specific features in Kener"cServlet, which is an
implementation of the basic, general purpose Servlet interface. (erlet:based
sessions are designed onl! for interactions using the HTT& protocol, which has
two ke! features necessar! for a serlet container to simulate continuous user
sessions: cookies and WRL:based naigation, which supports WRL:rewriting. The
serlet A&% therefore places the Htt!Sess"on interface in the
javax6servlet64tt! package, and session references are onl! aailable through
classes in this package.
Q: How can I assemble data from multiple input forms?
A: "irst, it is best to use a single serlet to handle each form submission. A single
serlet for all input would be too complicated. Yie each serlet responsibilit! to
alidate a single form input, and pass the error cases on to =(& documents that
e8plain the problem and allow users to amend the input.
Servlet concepts
Q: What's the difference between applets and servlets?
A: There are man! fundamental differences between A!!let and Servlet
classes, the =aa A&% documentation for the two t!pes will show !ou the! hae
little in common.
Applets are essentiall! graphical user interface 7YW%6 applications that run on the
client side in a network enironment, t!picall! embedded in an HT?L page.
Applets are normall! based on Abstract #indowing Toolkit components to
maintain backward:compatibilit! with the widest range of browsers@ =aa
implementations. The application classes are downloaded to the client and run in a
=aa 'irtual ?achine proided b! the browser, in a restrictie securit!
enironment called a Ksandbo8K.
(erlets are used to d!namicall! generate HTT& responses and return HT?L
content to #eb browsers on the serer side. (erlets are often used to alidate and
process HT?L form submissions and control a series of user interactions in what
is known as a #eb application. (erlets can be used to control all aspects of the
request and response e8change between a #eb browser and the serer, called a
serlet container.
Q: How can I write a servlet using 1avascript?
A: =aa serlets is a serer side technolog! that deliers d!namic content to #eb
browsers and other clients. =aascript is also deliered b! a #eb serer, but the
code is onl! interpreted and e8ecuted after it has been downloaded b! the #eb
browser. This means that it is not possible to write serlet code in =aascript.
&rasad '. &otluri (iddhartha %nstitute of Technolog! )*4
%t is possible to include =aascript in the output of serlets and =aa (erer &ages,
Bust like standard #eb pages. %t is also possible to d!namicall! generate =aascript
using a serlet and use it as the source for a script tag, though this is onl!
adisable in rare cases.
Q: How does the 1VM execute a servlet compared with a regular 1ava
class?
A: (erlets are standard =aa classes and are e8ecuted b! the =aa 'irtual
?achine in e8actl! the same wa! as an! other. Howeer, the enironment or
conte8t in which serlets are e8ecuted is different. A serlet is not inoked
directl! through a a"n method, the class is loaded and run b! a serlet container.
Can I include normal 1ava classes in servlets?
A: An! =aa class can be used in a #eb application, proided !ou make the
classes aailable to the serlet container at runtime. The =aa A&% classes can be
used directl! b! adding import statements to !our serlet class. >ther supporting
classes can also be imported, but these classes must be added to the classes or
l"b director! of !our application.
%f !ou need to configure the supporting classes, this can be done with standard
serlet configuration features using the ServletConf"# and ServletContext
obBects aailable to the "n"t%ServletConf"#& method.
Q: How can I tell when a servlet is instantiated?
A: A serlet must be instantiated before it is brought into serice b! the serlet
container, so one wa! to check is to make a request to the serlet and check the
response. %f !ou need to check indirectl!, !ou can oerride the
"n"t%ServletConf"#& method and add lo#%Str"n#& statements to it. This
method is called after the serlet container has instantiated the serlet before it is
brought into serice.
Q: What is URL-rewriting?
A: WRL:rewriting is a wa! of maintaining a session between an HTT& client and
a serlet container which does not use cookies. Rather than e8change a session %D
in a cookie, the serlet container includes it in the h!perlink WRLs it generates for
serlets and =(&.
: Are servlets multi-threaded?
&rasad '. &otluri (iddhartha %nstitute of Technolog! )*)
A: Zes, serlets are normall! multi:threaded. The serlet container allocates a
thread for each new request for a single serlet without an! special programming.
9ach thread of !our serlet runs as if a single user were accessing it alone, but
!ou can use static ariables to store and present information that is common to all
threads, like a hit counter for instance.
How can I pass values between 1SPs without using sessions?
A: There are four main alternaties to full session:based transfer of data alues,
two of them use features of the session tracking A&%: cookies and WRL:rewriting,
detailed below.
What is 1avaServer Pages technology?
=aa(erer &ages 7=(&6 technolog! proides a simplified, fast wa! to
create web pages that displa! d!namicall!:generated content. The =(&
specification, deeloped through an industr!:wide initiatie led b! (un
?icros!stems, defines the interaction between the serer and the =(&
page, and describes the format and s!nta8 of the page.
How does the 1avaServer Pages technology work?
=(& pages use X?L tags and scriptlets written in the =aa programming
language to encapsulate the logic that generates the content for the page. %t
passes an! formatting 7HT?L or X?L6 tags directl! back to the response
page. %n this wa!, =(& pages separate the page logic from its design and
displa!.
=(& technolog! is part of the =aa technolog! famil!. =(& pages are
compiled into serlets and ma! call =aa$eans components 7beans6 or
9nterprise =aa$eans components 7enterprise beans6 to perform
processing on the serer. As such, =(& technolog! is a ke! component in a
highl! scalable architecture for web:based applications.
=(& pages are not restricted to an! specific platform or web serer. The
=(& specification represents a broad spectrum of industr! input.
What is a servlet?
A serlet is a program written in the =aa programming language that runs
on the serer, as opposed to the browser 7applets6. Detailed information
can be found at http:DDBaa.sun.comDproductsDserlet.
Why do I need 1SP technology if I already have servlets?
=(& pages are compiled into serlets, so theoreticall! !ou could write
serlets to support !our web:based applications. Howeer, =(& technolog!
was designed to simplif! the process of creating pages b! separating web
&rasad '. &otluri (iddhartha %nstitute of Technolog! )**
presentation from web content. %n man! applications, the response sent to
the client is a combination of template data and d!namicall!:generated
data. %n this situation, it is much easier to work with =(& pages than to do
eer!thing with serlets.
Where can I get the most current version of the 1SP specification?
The =aa(erer &ages *.) specification is aailable for download from
here.
How does the 1SP specification relate to the 1ava Enterprise Edition 5 Platform?
The =(& *.) specification is an important part of the =aa 99 - &latform.
Wsing =(& and 9nterprise =aa$eans technologies together is a great wa!
to implement distributed enterprise applications with web:based front
ends.
Which web servers support 1SP technology?
There are a number of =(& technolog! implementations for different web
serers. The latest information on officiall!:announced support can be
found at http:DDBaa.sun.comDproductsDBspDindustr!.html.
Is Sun providing a reference implementation for the 1SP specification?
The Ylass"ish proBect is (un@s free, open:source =aa 99 -
implementation. %t includes an implementation of =(& technolog! ersion
*.). Zou can download Ylass"ish builds from
https:DDglassfish.de.Baa.netD.
How is 1SP technology different from other products?
=(& technolog! is the result of industr! collaboration and is designed to be
an open, industr!:standard method supporting numerous serers, browsers
and tools. =(& technolog! speeds deelopment with reusable components
and tags, instead of rel!ing heail! on scripting within the page itself. All
=(& implementations support a =aa programming language:based
scripting language, which proides inherent scalabilit! and support for
comple8 operations.
Where do I get more information on 1SP technology?
The first place to check for information on =(& technolog! is
http:DDBaa.sun.comDproductsDBspD. This site includes numerous resources,
as well as pointers to mailing lists and discussion groups for =(&
technolog!:related topics.
&rasad '. &otluri (iddhartha %nstitute of Technolog! )*+
&rasad '. &otluri (iddhartha %nstitute of Technolog! )*,

You might also like