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

Updated J2eelabmanual

1. This program inserts data into a student database table and retrieves information based on particular queries using JDBC drivers. It uses a Type 4 JDBC driver which converts JDBC calls directly into the database server's protocol. 2. The program defines methods to insert, select, view all, delete, and update student records in the database table. It uses PreparedStatement objects to execute precompiled SQL statements with placeholder parameters to improve performance. 3. Exceptions are handled to print stack traces if a database error occurs during execution. Connections are closed after completing operations to free up resources.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views

Updated J2eelabmanual

1. This program inserts data into a student database table and retrieves information based on particular queries using JDBC drivers. It uses a Type 4 JDBC driver which converts JDBC calls directly into the database server's protocol. 2. The program defines methods to insert, select, view all, delete, and update student records in the database table. It uses PreparedStatement objects to execute precompiled SQL statements with placeholder parameters to improve performance. 3. Exceptions are handled to print stack traces if a database error occurs during execution. Connections are closed after completing operations to free up resources.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 63

MASTER OF COMPUTER APPLICATIONS

IV SEMESTER
10MCA46 Scheme
J2EE Laborator
Com!"#e$ b %ar"&h '(M( a)$ Ma)*+ '
R.V.College of Engineering Dept. of MCA
CONTENTS
SL(
No(
,e&cr"!t"o) Pa-e
No(
1 VTU List of programs
4
2 Introduction to J2EE
6
3 Write a JAVA Program to insert data into tudent !ATA "AE and retrie#e info $ased on particu%ar
&ueries '&ueries can $e gi#en ()ic) co#ers a%% t)e topics of 2nd U*IT+,
8
4 Write a JAVA er#%et Program to imp%ement a d-namic .T/L using er#%et 'user name and pass(ord
s)ou%d $e accepted using .T/L and disp%a-ed using a er#%et+,
14
0 Write a JAVA er#%et Program to !o(n%oad a fi%e and disp%a- it on t)e screen 'A %in1 )as to $e
pro#ided in .T/L2 ()en t)e %in1 is c%ic1ed corresponding fi%e )as to $e disp%a-ed on creen+,
13
6 Write a JAVA er#%et Program to imp%ement 4e&uest!ispatc)er o$5ect 'use inc%ude'+ and for(ard'+
met)ods+,
16
3 Write a JAVA er#%et Program to imp%ement and demonstrate get'+ and Post met)ods'Using .TTP
er#%et 7%ass+,
22
8 Write a JAVA er#%et Program to imp%ement send4edirect'+ met)od'using .TTP er#%et 7%ass+, 20
6 Write a JAVA er#%et Program to imp%ement sessions 'Using .TTP ession Interface+,
23
19 a, Write a JAVA JP Program to print 19 e#en and 19 odd num$er,
$, Write a JAVA JP Program to imp%ement #erification of a particu%ar user %ogin and disp%a- a (e%come
page,
39
2
R.V.College of Engineering Dept. of MCA
11 Write a JAVA JP Program to get student information t)roug) a .T/L and create a JAVA "ean 7%ass2
popu%ate "ean and disp%a- t)e same information t)roug) anot)er JP,
34
12 Write a JP Program ()ic) uses :5sp;p%ugin< tag to run a app%et,
33
13 Write a JP Program ()ic) imp%ements nested tags and a%so uses Tagupport 7%ass,
36
14 An EJ" app%ication t)at demonstrates ession "ean,
42
10 An EJ" app%ication t)at demonstrates Entit- "ean,
48
16 An EJ" app%ication t)at demonstrates /!",
04
13 Vi#a &uestions and e=tra programs
69
18 J2EE La$ 7-c%es
62
3
R.V.College of Engineering Dept. of MCA
4
R.V.College of Engineering Dept. of MCA
,o.& a)$ ,o).t& ") the Laborator
,O /((
7ome prepared to t)e La$,
u$mit -our 4ecords to t)e Lecturer and sign in t)e Log "oo1 on
entering t)e La$,
>o%%o( t)e La$ c-c%es as instructed $- t)e !epartment, Vio%ating t)e
same (i%% resu%t in deduction of mar1s,
Use t)e same %ogin 'if an-+ assigned to -ou,
Put t)e c)airs $ac1 to its position $efore -ou %ea#e,
"ac1%og e=ercises to $e e=ecuted after comp%eting regu%ar e=ercises,
?eep -our premises c%ean,
,ON.T /((
/o#e around in t)e %a$ during t)e %a$ session,
Tamper -stem >i%es or Tr- to access t)e er#er,
Write !ata )eets or 4ecords in t)e La$
7)ange t)e s-stem assigned to -ou (it)out t)e notice of t)e La$ taff,
Write on t)e ta$%e or mouse pads,
Teac)ing -our friends during %a$ sessions,
0
R.V.College of Engineering Dept. of MCA
I)tro$+ct"o) to J2EE
J2EE 'Ja#a 2 P%atform2 Enterprise Edition+ is a Ja#a p%atform designed for t)e mainframe@sca%e
computing t-pica% of %arge enterprises, un /icros-stems 'toget)er (it) industr- partners suc)
as I"/+ designed J2EE to simp%if- app%ication de#e%opment in a t)in c%ient tiered en#ironment,
J2EE simp%ifies app%ication de#e%opment and decreases t)e need for programming and
programmer training $- creating standardiAed2 reusa$%e modu%ar components and $- ena$%ing t)e
tier to )and%e man- aspects of programming automatica%%-,
J2EE inc%udes man- components of t)e Ja#a 2 P%atform2 tandard Edition 'J2E+;
T)e Ja#a !e#e%opment ?it 'J!?+ is inc%uded as t)e core %anguage pac1age,
Write Once Run Anywhere tec)no%og- is inc%uded to ensure porta$i%it-,
upport is pro#ided for 7ommon B$5ect 4e&uest "ro1er Arc)itecture '7B4"A+2 a predecessor
of Enterprise Ja#a"eans 'EJ"+2 so t)at Ja#a o$5ects can communicate (it) 7B4"A o$5ects $ot)
%oca%%- and o#er a net(or1 t)roug) its interface broker,
Ja#a !ata$ase 7onnecti#it- 2,9 'J!"7+2 t)e Ja#a e&ui#a%ent to Bpen !ata$ase 7onnecti#it-
'B!"7+2 is inc%uded as t)e standard interface for Ja#a data$ases,
A securit- mode% is inc%uded to protect data $ot) %oca%%- and in We$@$ased app%ications,
J2EE a%so inc%udes a num$er of components added to t)e J2E mode%2 suc) as t)e fo%%o(ing;
>u%% support is inc%uded for Enterprise Ja#a"eans, EJ" is a ser#er@$ased tec)no%og- for t)e
de%i#er- of program components in an enterprise en#ironment, It supports t)e E=tensi$%e /ar1up
Language 'C/L+ and )as en)anced dep%o-ment and securit- features,
T)e Ja#a ser#%et API 'app%ication programming interface+ en)ances consistenc- for de#e%opers
(it)out re&uiring a grap)ica% user interface 'DUI+,
Ja#a er#er Pages 'JP+ is t)e Ja#a e&ui#a%ent to /icrosoftEs Acti#e er#er Pages 'AP+ and is
used for d-namic We$@ena$%ed data access and manipu%ation,
T)e J2EE arc)itecture consists of four ma5or e%ements;
T)e J2EE App%ication Programming /ode% is t)e standard programming mode% used to faci%itate
t)e de#e%opment of mu%ti@tier2 t)in c%ient app%ications,
T)e J2EE P%atform inc%udes necessar- po%icies and APIs suc) as t)e Ja#a ser#%ets and Ja#a
/essage er#ice 'J/+,
T)e J2EE 7ompati$i%it- Test uite ensures t)at J2EE products are compati$%e (it) t)e p%atform
standards,
T)e J2EE 4eference Imp%ementation e=p%ains J2EE capa$i%ities and pro#ides its operationa%
definition,
6
R.V.College of Engineering Dept. of MCA
3
Solution
s
R.V.College of Engineering Dept. of MCA
1( 0r"te a JAVA Pro-ram to ")&ert $ata ")to St+$e)t ,ATA 1ASE a)$ retr"e2e ")3o ba&e$
o) !art"c+#ar 4+er"e& 54+er"e& ca) be -"2e) 6h"ch co2er& a## the to!"c& o3 2)$ UNIT7(
J!"7 dri#ers are di#ided into four t-pes or %e#e%s, Eac) t-pe defines a J!"7 dri#er
imp%ementation (it) increasing%- )ig)er %e#e%s of p%atform independence2 performance2 and
dep%o-ment administration, T)e four t-pes are;
T-pe 1; J!"7@B!"7 "ridge
T-pe 2; *ati#e@APIFpart%- Ja#a dri#er
T-pe 3; *et@protoco%Fa%%@Ja#a dri#er
T-pe 4; *ati#e@protoco%Fa%%@Ja#a dri#er
In t)is program (e )a#e used T-pe 4 dri#er'/-&%connector 0,1 for /-&% er#er+
T)e nati#e@protoco%Fa%%@Ja#a dri#er 'J!"7 dri#er t-pe 4+ con#erts J!"7 ca%%s into t)e
#endor@specific data$ase management s-stem '!"/+ protoco% so t)at c%ient
app%ications can communicate direct%- (it) t)e data$ase ser#er, Le#e% 4 dri#ers are
comp%ete%- imp%emented in Ja#a to ac)ie#e p%atform independence and e%iminate
dep%o-ment administration issues,
T)e PreparedStatement o$5ect represents t)e precompi%ed S8L statement, W)ene#er2 t)e S8L
statement is precompi%ed t)en it stored in t)e PreparedStatement o$5ect ()ic) e=ecutes t)e
statement man- times and it reduces t)e time duration of e=ecution, T)e PreparedStatement
uses t)e 9:9 (it) GL statement t)at pro#ides t)e faci%it- for setting an appropriate conditions
in it
Pro-ram;
import 5a#a,s&%,HI
import 5a#a,uti%,cannerI
pu$%ic c%ass student J

7onnection conI
pu$%ic #oid insert'tring name2tring usn2tring pass+
J
tr- J
connectd$'+I
Preparedtatement pre K con,preparetatement'Linsert into
student'name2usn2resu%t+ #a%ues'M2M2M+L+I
pre,settring'12name+I
pre,settring'22usn+I
pre,settring'32pass+I
int rs Kpre,e=ecuteUpdate'+I
if'rsKK1+
J
-stem,out,print%n'L4EULT UP!ATE!L+I
8
R.V.College of Engineering Dept. of MCA
con,c%ose'+I
N
e%se
J
-stem,out,print%n'LUP!ATIB* >AILE!L+I
con,c%ose'+I
N
N
catc)'E=ception e+
J
e,printtac1Trace'+I
N

N
pu$%ic #oid se%ect 'tring usn+
J
tr- J
connectd$'+I
Preparedtatement pre K con,preparetatement'Lse%ect H from student ()ere usn
KML+I
pre,settring'12usn+I
4esu%tet rs K pre,e=ecuteGuer-'+I

if'rs,ne=t'++
J
-stem,out,print%n'L*ameK LOrs,gettring'1++I
-stem,out,print%n'LU*K LOrs,gettring'2++I
-stem,out,print%n'L4esu%tK LOrs,gettring'3++I
con,c%ose'+I
N
e%se
J
-stem,out,print%n'LELE7TIB* >AILE!L+I
con,c%ose'+I
N
N
catc)'E=ception e+
J
e,printtac1Trace'+I
N

N
pu$%ic #oid #ie(a%% '+
J
6
R.V.College of Engineering Dept. of MCA
tr- J
connectd$'+I
Preparedtatement pre K con,preparetatement'Lse%ect H from studentL+I
4esu%tet rs K pre,e=ecuteGuer-'+I
()i%e'rs,ne=t'++
J
-stem,out,print%n'rs,gettring'1+OL LOrs,gettring'2+OL
LOrs,gettring'3++I
N
con,c%ose'+I
N
catc)'E=ception e+
J
e,printtac1Trace'+I
N
N

pu$%ic #oid de%ete 'tring usn+
J

tr- J
connectd$'+I
Preparedtatement pre K con,preparetatement'Lde%ete from student ()ere usn
KML+I
pre,settring'12usn+I
int rs K pre,e=ecuteUpdate'+I

if'rsKK1+
J
-stem,out,print%n'L4E7B4! UP!ATE!L+I
con,c%ose'+I
N
e%se
J
-stem,out,print%n'LUP!ATIB* >AILE!L+I
con,c%ose'+I
N
N
catc)'E=ception e+
J
e,printtac1Trace'+I

N
N

pu$%ic #oid update'tring name2tring usn2tring pass+
19
R.V.College of Engineering Dept. of MCA
J

tr- J
connectd$'+I
Preparedtatement pre K con,preparetatement'Lupdate student set name
K M2resu%t K M ()ere usn K M L+I
pre,settring'12name+I
pre,settring'22pass+I
pre,settring'32usn+I
int rs Kpre,e=ecuteUpdate'+I
if'rsKK1+
J
-stem,out,print%n'L4EULT UP!ATE!L+I

con,c%ose'+I
N
e%se
J
-stem,out,print%n'LUP!ATIB* >AILE!L+I
con,c%ose'+I
N
N
catc)'E=ception e+
J
e,printtac1Trace'+I
N
N
pu$%ic #oid connectd$'+
J
tr- J
7%ass,for*ame'Lcom,m-s&%,5d$c,!ri#erL+I
conK!ri#er/anager,get7onnection'L5d$c;m-s&%;FF%oca%)ost;3396F5d$cL2LrootL2L)aris)L+I
N
catc)'E=ception e+
J
e,printtac1Trace'+I

N
N
pu$%ic static #oid main'tringPQ args+ J
student sd$ K ne( student'+I
tring n2p2uI
()i%e'true+
J
11
R.V.College of Engineering Dept. of MCA
-stem,out,print%n'L1 to insert dataL+I
-stem,out,print%n'L2 to se%ect dataL+I
-stem,out,print%n'L3 to update dataL+I
-stem,out,print%n'L4 to de%ete dataL+I
-stem,out,print%n'L0 to #ie( a%%L+I
canner s K ne( canner'-stem,in+I

s(itc)'s,ne=tInt'++
J
case 1;
-stem,out,print%n'LEnter nameL+I
nKs,ne=t'+I
-stem,out,print%n'LEnter U*L+I
uKs,ne=t'+I
-stem,out,print%n'LpassFfai%L+I
pKs,ne=t'+I
sd$,insert'n2u2p+I
$rea1I
case 2;
-stem,out,print%n'LEnter U* to searc)L+I
uKs,ne=t'+I
sd$,se%ect'u+I
$rea1I
case 3;
-stem,out,print%n'LEnter nameL+I
nKs,ne=t'+I
-stem,out,print%n'LEnter U*L+I
uKs,ne=t'+I
-stem,out,print%n'LpassFfai%L+I
pKs,ne=t'+I
sd$,update'n2u2p+I
$rea1I
case 4;
-stem,out,print%n'LEnter U* to !e%eteL+I
uKs,ne=t'+I
sd$,de%ete'u+I
$rea1I
case 0;
-stem,out,print%n'LHHHHHHHHHHHHH>ILE 7B*TE*THHHHHHHHHHHHHHHHHHL+I
sd$,#ie(a%%'+I
$rea1I
defau%t; -stem,e=it'9+I

N
N

12
R.V.College of Engineering Dept. of MCA
N
N
Te&t ,ata;
set 7LAPAT. for m-s&%connector,5ar fi%e in ,$as)rc fi%e,
)aris)R)aris)@%aptop;SF%a$T 5a#ac student,5a#a
)aris)R)aris)@%aptop;SF%a$T 5a#a student
1 to insert data
2 to se%ect data
3 to update data
4 to de%ete data
0 to #ie( a%%
13
R.V.College of Engineering Dept. of MCA
2, 0r"te a JAVA Ser2#et Pro-ram to "m!#eme)t a $)am"c %TML +&")- Ser2#et 5+&er
)ame a)$ !a&&6or$ &ho+#$ be acce!te$ +&")- %TML a)$ $"&!#ae$ +&")- a Ser2#et7(
A servlet is a Ja#a programming %anguage c%ass used to e=tend t)e capa$i%ities of ser#ers t)at
)ost app%ications accessed #ia a re&uest@response programming mode%, A%t)oug) ser#%ets can
respond to an- t-pe of re&uest2 t)e- are common%- used to e=tend t)e app%ications )osted $-
We$ ser#ers, >or suc) app%ications2 Ja#a er#%et tec)no%og- defines .TTP@specific ser#%et
c%asses,
T)e 5a#a=,ser#%et and 5a#a=,ser#%et,)ttp pac1ages pro#ide interfaces and c%asses for (riting
ser#%ets, A%% ser#%ets must imp%ement t)e er#%et interface2 ()ic) defines %ife@c-c%e met)ods,
T)e %ife c-c%e of a ser#%et is contro%%ed $- t)e container in ()ic) t)e ser#%et )as $een dep%o-ed,
W)en a re&uest is mapped to a ser#%et2 t)e container performs t)e fo%%o(ing steps,
1, If an instance of t)e ser#%et does not e=ist2 t)e We$ container
a( Loads t)e ser#%et c%ass,
b( 7reates an instance of t)e ser#%et c%ass,
c( Initia%iAes t)e ser#%et instance $- ca%%ing t)e init met)od, Initia%iAation is co#ered
in Initia%iAing a er#%et,
2, In#o1es t)e ser#ice met)od2 passing a re&uest and response o$5ect, er#ice met)ods are
discussed in t)e section Writing er#ice /et)ods,
If t)e container needs to remo#e t)e ser#%et2 it fina%iAes t)e ser#%et $- ca%%ing t)e ser#%etEs destro-
met)od, >ina%iAation is discussed in >ina%iAing a er#%et,
Pro-ram;
FFpost,5a#a
import 5a#a,io,HI
import 5a#a,uti%,HI
import 5a#a=,ser#%et,HI
pu$%ic c%ass post e=tends Denericer#%et
J
pu$%ic #oid ser#ice'er#%et4e&uest re&uest2
er#%et4esponse response+
t)ro(s er#%etE=ception2IBE=ception
J
PrintWriter p( K response,getWriter'+I
Enumeration e K re&uest,getParameter*ames'+I
()i%e'e,)as/oreE%ements'+ +
J
tring pnameK'tring+e,ne=tE%ement'+I
14
R.V.College of Engineering Dept. of MCA
p(,print'pname+I
tring p#a%ueKre&uest,getParameter'pname+I
p(,print%n'p#a%ue+I
N
p(,c%ose'+I
N
N
post,)tm%
:)tm%<
:$od-<
:center<
:form nameKLform1L met)od KLpostL
actionKL)ttp;FF%oca%)ost;8989Fe=amp%esFser#%etsFser#%etFpostL<
:ta$%e<
:tr<
:td<:"<Username:Ftd<
:td<:input t-peKte=t$o= nameKLusernameL<:Ftd<
:Ftr<
:tr<
:td<:"<Pass(ord:Ftd<
:td<:input t-peKte=t$o= nameKLpass(ordL<:Ftd<
:Ftr<
:Fta$%e<
:input t-peKsu$mit #a%ueKLsu$mitL<
:Fform<
:F$od-<
:F)tm%<
Te&t ,ata;
assuming tomcat6 O sun@6@5d1 is insta%%ed proper%-
if insta%%ed from s-naptic pac1age manager tocat6 is insta%%ed as $e%o(
FusrFs)areFtomcat6
FusrFs)areFtomcat6@e=amp%es
10
R.V.College of Engineering Dept. of MCA
in tomcat6@e=amp%esFe=amp%esFWE"@I*>Fc%assesT
p%ace t)e :post,5a#a< and :post,c%ass< in t)e WE"@I*> director-
p%ace t)e post,)tm% fi%e in
FusrFs)areFtomcat6@e=amp%esFe=amp%esFser#%ets director-
assuming Tomcat is running on port 8989 re&uest as $e%o(
)ttp;FF%oca%)ost;8989Fe=amp%esFser#%etsFser#%etFpost
u (i%% get output as
pass(ord
username
)aris)
)ari
16
R.V.College of Engineering Dept. of MCA
<( 0r"te a JAVA Ser2#et Pro-ram to ,o6)#oa$ a 3"#e a)$ $"&!#a "t o) the &cree) 5A #")=
ha& to be !ro2"$e$ ") %TML> 6he) the #")= "& c#"c=e$ corre&!o)$")- 3"#e ha& to be
$"&!#ae$ o) Scree)7(
T)e doDet and doPost met)ods are ca%%ed in response to an .TTP DET and an .TTP PBT
respecti#e%- ()ic) are su$mission met)ods used in an .T/L >B4/, Bn an .TTP DET t)e
form data is part of t)e U4L ()ereas on an .TTP PBT t)e form data appears in t)e
message $od-, Uou s)ou%d a%(a-s )a#e one met)od ca%% t)e ot)er in -our ser#%et as
processing t)e form data in a ser#%et is consistent regard%ess of t)e su$mission met)od,
doDet'+; T)e doDet'+ met)od of t)e er#%et is automatica%%- ca%%ed ()en a c%ient in#o1es a
er#%et $- c%ic1ing on a %in1, T)e doDet'+ met)od is ca%%ed $- t)e ser#ice'+ met)od ()en it
recei#es a DET re&uest, T)is met)od is ca%%ed ()en a user c%ic1s on a %in12 enters a U4L into t)e
$ro(serVs address $ar2 or su$mits an .T/L form (it) /ET.B!KWDETW specified in t)e
>B4/ tag,
doPost'+; T)e doPost'+ met)od of t)e er#%et is in#o1ed ()en t)e $ro(ser sends an .TTP
re&uest using t)e post'+ met)od,
>or e=amp%e2 if a user is going to ca%% a er#%et $- c%ic1ing on a %in12 t)e doDet'+ met)od is used,
If t)e user is fi%%ing out a form and sends t)e data to t)e ser#er2 t)e doPost'+ met)od is used, T)e
doDet'+ and doPost'+ met)ods are part of t)e .TTP protoco%, "ot) met)ods are ca%%ed $- t)e
defau%t 'superc%ass+ imp%ementation of ser#ice in t)e .ttper#%et $ase c%ass,
Pro-ram;
import 5a#a=,ser#%et,HI
import 5a#a=,ser#%et,)ttp,HI
import 5a#a,io,HI
pu$%ic c%ass >i%e!o(n%oads e=tends .ttper#%et
J
pu$%ic #oid doDet'.ttper#%et4e&uest re&2.ttper#%et4esponse res+t)ro(s er#%etE=ception2
IBE=ception J
PrintWriter out K res,getWriter'+I
out,print%n'L:)tm%<:)ead<!o(n%oad a >i%e E=amp%e:F)ead<:F)tm%<L+I
out,print%n'L:pre<:a )refK!,5a#a< c%ic1 )ere to do(n%oad !,5a#a fi%e :Fa<:$r< L+I
out,print%n'L:pre<:a )refK,5a#a< c%ic1 )ere to do(n%oad ,5a#a fi%e :Fa< L+I
out,print%n'L:pre<:a )refKas1mea$tfreesoft(are,png< c%ic1 )ere to do(n%oad
as1mea$tfreesoft(are,png fi%e :Fa<:$r< L+I
out,print%n'L:pre<:a )refKfsf)ead,pdf< c%ic1 )ere to do(n%oad fsf)ead,pdf fi%e :Fa< L+I
out,print%n'L:pre<:a )refKpigeon,5pg< c%ic1 )ere to do(n%oad pigeon,5pg fi%e :Fa<:$r< L+I
out,print%n'L:pre<:a )refKsta%%man,5pg< c%ic1 )ere to do(n%oad sta%%man,5pg fi%e :Fa< L+I
N
N
t)e )-per %in1s t)at are gi#en in t)e a$o#e program are pointing to t)ose fi%es t)at are present in
t)e
main director- t)at is )ere FusrFs)areFtomcat6@e=amp%esFe=amp%es
ma1e entries in t)e (e$,=m% fi%e

13
R.V.College of Engineering Dept. of MCA
:ser#%et<
:ser#%et@ame<>i%e!o(n%oads:Fser#%et@name<
:ser#%et@c%ass<>i%e!o(n%oads:Fser#%et@c%ass<
:Fser#%et<

:ser#%et@mapping<
:ser#%et@name<>i%e!o(n%oads:Fser#%et@name<
:ur%@pattern<F>i%e!o(n%oads:Fur%@pattern<
:Fser#%et@mapping<
Te&t ,ata;
W)en tomcat is running re&uest for t)e ser#%et at )ttp;FF%oca%)ost;8989Fe=amp%es for
>i%e!o(n%oads i,e )ttp;FF%oca%)ost;8989Fe=amp%esF>i%e!o(n%oads -ou (i%% get %in1s to se#era%
fi%es
on t)e page ()ic) ()en c%ic1ed opens corresponding fi%es in t)e $ro(ser if t)e supportting
p%ugin
is present e%se e=terna% app%ication (i%% $e used %i1e e#ince for pdf fi%es 'in m- case as i )ad not
insta%%ed pdf p%ugins for $ro(ser+ ,
18
R.V.College of Engineering Dept. of MCA
4( 0r"te a JAVA Ser2#et Pro-ram to "m!#eme)t Re4+e&t,"&!atcher ob*ect 5+&e ")c#+$e57
a)$ 3or6ar$57 metho$&7(
Re4+e&t,"&!atcher
!efines an o$5ect t)at recei#es re&uests from t)e c%ient and sends t)em to an- resource 'suc) as a
ser#%et2 .T/L fi%e2 or JP fi%e+ on t)e ser#er, T)e ser#%et container creates t)e
4e&uest!ispatc)er o$5ect2 ()ic) is used as a (rapper around a ser#er resource %ocated at a
particu%ar pat) or gi#en $- a particu%ar name,
T)is interface is intended to (rap ser#%ets2 $ut a ser#%et container can create 4e&uest!ispatc)er
o$5ects to (rap an- t-pe of resource,
3or6ar$
#oid 3or6ar$'er#%et4e&uest re&uest2
er#%et4esponse response+
t)ro(s er#%etE=ception2
IBE=ception
>or(ards a re&uest from a ser#%et to anot)er resource 'ser#%et2 JP fi%e2 or .T/L fi%e+ on t)e
ser#er, T)is met)od a%%o(s one ser#%et to do pre%iminar- processing of a re&uest and anot)er
resource to generate t)e response,
>or a 4e&uest!ispatc)er o$tained #ia get4e&uest!ispatc)er'+2 t)e er#%et4e&uest o$5ect )as its
pat) e%ements and parameters ad5usted to matc) t)e pat) of t)e target resource,
")c#+$e
#oid ")c#+$e'er#%et4e&uest re&uest2
er#%et4esponse response+
t)ro(s er#%etE=ception2
IBE=ception
Inc%udes t)e content of a resource 'ser#%et2 JP page2 .T/L fi%e+ in t)e response, In essence2 t)is
met)od ena$%es programmatic ser#er@side inc%udes,
T)e er#%et4esponse o$5ect )as its pat) e%ements and parameters remain unc)anged from t)e
ca%%erEs, T)e inc%uded ser#%et cannot c)ange t)e response status code or set )eadersI an- attempt
to ma1e a c)ange is ignored,
Pro-ram;
import 5a#a=,ser#%et,4e&uest!ispatc)erI
import 5a#a=,ser#%et,er#%etE=ceptionI
import 5a#a=,ser#%et,)ttp,.ttper#%etI
import 5a#a=,ser#%et,)ttp,.ttper#%et4e&uestI
import 5a#a=,ser#%et,)ttp,.ttper#%et4esponseI
16
R.V.College of Engineering Dept. of MCA
pu$%ic c%ass /u%tip%eInc%ude e=tends .ttper#%et J
protected #oid doDet'.ttper#%et4e&uest re&uest2
.ttper#%et4esponse response+ t)ro(s er#%etE=ception2
5a#a,io,IBE=ception J
response,set7ontentT-pe'Lte=tF)tm%L+I
5a#a,io,PrintWriter out K response,getWriter'+I
out,print%n'L:)tm%<L+I
out,print%n'L:)ead<L+I
out,print%n'L:tit%e</u%tip%e Inc%udes:Ftit%e<L+I
out,print%n'L:F)ead<L+I
out,print%n'L:$od-<L+I
out,print%n'L:)1<.e%%o from Le#e% 1:F)1<L+I
out,print%n'LT)is te=t is disp%a-ed at Le#e% 1,L+I
4e&uest!ispatc)er dispatc)er K re&uest,get4e&uest!ispatc)er'LF
Le#e%4L+I
dispatc)er,inc%ude're&uest2 response+I
out,print%n'L:F$od-<L+I
out,print%n'L:F)tm%<L+I
out,c%ose'+I
N
N
:X@@ (e$,=m% @@<
:ser#%et<
:ser#%et@name</u%tip%eInc%ude:Fser#%et@name<
:ser#%et@c%ass</u%tip%eInc%ude:Fser#%et@c%ass<
:Fser#%et<
:ser#%et@mapping<
:ser#%et@name</u%tip%eInc%ude:Fser#%et@name<
:ur%@pattern<F/u%tip%eInc%ude:Fur%@pattern<
:Fser#%et@mapping<
:ser#%et<
:ser#%et@name<Le#e%4:Fser#%et@name<
:ser#%et@c%ass<Le#e%4:Fser#%et@c%ass<
29
R.V.College of Engineering Dept. of MCA
:Fser#%et<
:ser#%et@mapping<
:ser#%et@name<Le#e%4:Fser#%et@name<
:ur%@pattern<FLe#e%4:Fur%@pattern<
:Fser#%et@mapping<
FF )ere is anot)er ser#%et
import 5a#a=,ser#%et,er#%etE=ceptionI
import 5a#a=,ser#%et,)ttp,.ttper#%etI
import 5a#a=,ser#%et,)ttp,.ttper#%et4e&uestI
import 5a#a=,ser#%et,)ttp,.ttper#%et4esponseI
pu$%ic c%ass Le#e%4 e=tends .ttper#%et J

protected #oid doDet'.ttper#%et4e&uest re&uest2
.ttper#%et4esponse response+
t)ro(s er#%etE=ception2 5a#a,io,IBE=ception J

5a#a,io,PrintWriter out K response,getWriter'+I
out,print%n'L:)4<.e%%o from anot)er doDet:F)4<L+I
out,print%n'L.e%%o from anot)er doDet,L+I
N
N
Te&t ,ata;
)ttp;FF%oca%)ost;8989Fe=amp%esF/u%tip%eInc%ude
.e%%o from Le#e% 1
T)is te=t is disp%a-ed at Le#e% 1,
.e%%o from anot)er doDet
.e%%o from anot)er doDet,
)ttp;FF%oca%)ost;8989Fe=amp%esFLe#e%4
.e%%o from anot)er doDet
.e%%o from anot)er doDet,
dispatc)er,inc%ude're&uest2 response+I so /u%tip%eInc%ude co%%ects response from t)e Le#e%4
21
R.V.College of Engineering Dept. of MCA
0, 0r"te a JAVA Ser2#et Pro-ram to "m!#eme)t a)$ $emo)&trate -et57 a)$ Po&t
metho$&5U&")- %TTP Ser2#et C#a&&7(
T)e doDet and doPost met)ods are ca%%ed in response to an .TTP DET and an .TTP PBT
respecti#e%- ()ic) are su$mission met)ods used in an .T/L >B4/, Bn an .TTP DET t)e
form data is part of t)e U4L ()ereas on an .TTP PBT t)e form data appears in t)e
message $od-, Uou s)ou%d a%(a-s )a#e one met)od ca%% t)e ot)er in -our ser#%et as
processing t)e form data in a ser#%et is consistent regard%ess of t)e su$mission met)od,
doDet'+; T)e doDet'+ met)od of t)e er#%et is automatica%%- ca%%ed ()en a c%ient in#o1es a
er#%et $- c%ic1ing on a %in1, T)e doDet'+ met)od is ca%%ed $- t)e ser#ice'+ met)od ()en it
recei#es a DET re&uest, T)is met)od is ca%%ed ()en a user c%ic1s on a %in12 enters a U4L into t)e
$ro(serVs address $ar2 or su$mits an .T/L form (it) /ET.B!KWDETW specified in t)e
>B4/ tag,
doPost'+; T)e doPost'+ met)od of t)e er#%et is in#o1ed ()en t)e $ro(ser sends an .TTP
re&uest using t)e post'+ met)od,
>or e=amp%e2 if a user is going to ca%% a er#%et $- c%ic1ing on a %in12 t)e doDet'+ met)od is used,
If t)e user is fi%%ing out a form and sends t)e data to t)e ser#er2 t)e doPost'+ met)od is used, T)e
doDet'+ and doPost'+ met)ods are part of t)e .TTP protoco%, "ot) met)ods are ca%%ed $- t)e
defau%t 'superc%ass+ imp%ementation of ser#ice in t)e .ttper#%et $ase c%ass,
Pro-ram;
:)tm%<
:$od-<
:center<
:form nameKLform1L met)odKpost
actionKL)ttp;FF%oca%)ost;8989Fe=amp%esFser#%etsFser#%etFco%orpostL
<
:"<co%or;:F"<
:se%ect nameKLco%orLsiAeKL1L<
:option #a%ueKLredL<red:Foption<
:option #a%ueKLgreenL<green:Foption<
:option #a%ueKL$%ueL<$%ue:Foption<
:Fse%ect<
:$r<:$r<
:input t-peKsu$mit #a%ueKLsu$mitL<
:Fform<
:F$od-<
:F)tm%<
import 5a#a,io,HI
import 5a#a=,ser#%et,HI
import 5a#a=,ser#%et,)ttp,HI
pu$%ic c%ass co%orpost e=tends .ttper#%et
J

22
R.V.College of Engineering Dept. of MCA
pu$%ic #oid doPost'.ttper#%et4e&uest re&uest2
.ttper#%et4esponse response+
t)ro(s er#%etE=ception2IBE=ception
J

tring co%orKre&uest,getParameter'Lco%orL+I
response,set7ontentT-pe'Lte=tF)tm%L+I
PrintWriter p(Kresponse,getWriter'+I
p(,print%n'Lt)e se%ected co%or is;L+I
p(,print%n'co%or+I
p(,c%ose'+I
N
N
Te&t ,ata;
after appropriate entries in
fi%e;FFFusrFs)areFtomcat6@
e=amp%esFe=amp%esFser#%etsFco%orpost,)tm% ()i%e re&uest is done
)ttp;FF%oca%)ost;8989Fe=amp%esFser#%etsFser#%etFco%orpost
respose (i%% )a#e t)is on address$ar
and out put is
t)e se%ected co%or is; green
if green (as se%ected from t)e options,
@@@@@@@@@@@@@configuration entries )a#e to $e made in (e$,=m% as done in pre#ious e=amp%e
@@@@@@@@@@@@@using DET
import 5a#a,io,HI
import 5a#a=,ser#%et,HI
import 5a#a=,ser#%et,)ttp,HI
pu$%ic c%ass co%or e=tends .ttper#%et
J

pu$%ic #oid doDet'.ttper#%et4e&uest re&uest2
.ttper#%et4esponse response+
t)ro(s er#%etE=ception2IBE=ception
J

tring co%orKre&uest,getParameter'Lco%orL+I
response,set7ontentT-pe'Lte=tF)tm%L+I
PrintWriter p(Kresponse,getWriter'+I
p(,print%n'Lt)e se%ected co%or is;L+I
p(,print%n'co%or+I
p(,c%ose'+I
N
N
:)tm%<
23
R.V.College of Engineering Dept. of MCA
:$od-<
:center<
:form nameKLform1L
actionKL)ttp;FF%oca%)ost;8989Fe=amp%esFser#%etsFser#%etFco%orL<
:"<co%or;:F"<
:se%ect nameKLco%orLsiAeKL1L<
:option #a%ueKLredL<red:Foption<
:option #a%ueKLgreenL<green:Foption<
:option #a%ueKL$%ueL<$%ue:Foption<
:Fse%ect<
:$r<:$r<
:input t-peKsu$mit #a%ueKLsu$mitL<
:Fform<
:F$od-<
:F)tm%<
Te&t ,ata;
)ttp;FF%oca%)ost;8989Fe=amp%esFser#%etsFser#%etFco%orMco%orKred
)ttp;FF%oca%)ost;8989Fe=amp%esFser#%etsFser#%etFco%orMco%orK$%ac1
' manua%%- on t)e address $ar ()ate#er it is gi#en t)en t)e
ser#%et (i%% respond according%- 2ot)ersie a%so co%or,)tm% (i%%
gi#e a c)ance to see t)e effect ,
24
R.V.College of Engineering Dept. of MCA
6( 0r"te a JAVA Ser2#et Pro-ram to "m!#eme)t &e)$Re$"rect57 metho$5+&")- %TTP
Ser2#et C#a&&7(
&e)$Re$"rect57 met)od is a met)od of HttpServletResponse interface, W)en a c%ient sends a
re&uest for a particu%ar page to a ser#er and ser#er sees t)at t)is re&uest is canEt $e performed
$- t)is page2 t)en it sends a error code to t)e $ro(ser specif-ing t)at t)e re&uest canEt $e
performed $- t)is page, A%ong (it) t)e error code it a%so gi#es t)e address of t)e page ()ic)
(i%% $e a$%e to perform t)e re&uest of t)e c%ient, In &e)$Re$"rect57 t)e o$5ect of re&uest (i%%
$e generated again (it) t)e %ocation of page ()ic) (i%% perform t)e re&uest of t)e c%ient,
Pro-ram;
FF!,5a#a
import 5a#a=,ser#%et,HI
import 5a#a=,ser#%et,)ttp,HI
import 5a#a,io,HI
pu$%ic c%ass ! e=tends .ttper#%et
J
pu$%ic #oid doDet'.ttper#%et4e&uest re&2.ttper#%et4esponse
res+t)ro(s er#%etE=ception2 IBE=ception
J
PrintWriter out K res,getWriter'+I
out,print%n'L:)tm%<:)ead<end4edirect'+
E=amp%e:F)ead<:F)tm%<L+I
out,print%n'L:$od-<:center<:font co%orKred siAe K 34</-We$ :F
font<L+I
out,print%n'L:pre<:a )refK<earc):Fa< :a
)refK!<greetings:Fa< :Fpre<L+I
out,print%n'L:ta$%e $order K 12 (idt) K 199 <L+I
out,print%n'L:tr<:t)<*B:Ft)<:t)<",name:Ft)<:t)<Gua%it-:Ft)<:Ftr<L
+I
out,print%n'L:tr<:td<1:Ftd<:td<J2E:Ftd<:td<19:Ftd<:Ftr<L+I
out,print%n'L:tr<:td<2:Ftd<:td<J2EE:Ftd<:td<19:Ftd<:Ftr<L+I
out,print%n'L:Fta$%e<:Fcenter<:F$od-<:F$od-<L+I
N
N
FF,5a#a
import 5a#a=,ser#%et,HI
import 5a#a=,ser#%et,)ttp,HI
import 5a#a,io,HI
pu$%ic c%ass e=tends .ttper#%et
J
pu$%ic #oid doDet'.ttper#%et4e&uest re&2.ttper#%et4esponse
res+t)ro(s er#%etE=ception2 IBE=ception
J res,send4edirect'L)ttp;FF%oca%)ost;8989Fe=amp%esF5spFinde=,)tm%L
20
R.V.College of Engineering Dept. of MCA
+I
N
N
Te&t ,ata;
)aris)R)aris)@%aptop;SF)omeFr#cemcaF!ocumentsF5a#aF%a$@4semFser#%ets
5a#ac @cp F)omeFr#cemcaFnet$eans@6,0Fide19Fmodu%esFe=tFm-s&%@connector@5a#a@0,1,6@
$in,5ar !!,5a#a
5a#ac @cp F)omeFr#cemcaFnet$eans@6,0Fide19Fmodu%esFe=tFm-s&%@connector@5a#a@0,1,6@
$in,5ar ,5a#a
p%ace t)e !!,5a#a2!!,c%ass2,5a#a2,c%ass fi%es in t)e director-
FusrFs)areFtomcat6@e=amp%esFe=amp%esFWE"@I*>Fc%asses
from t)e $ro(ser Y)ttp;FF%oca%)ost;8989Fe=amp%esF!W -ou (i%% reac) a page t)ere c%ic1 on t(o
%in1s
pro#ided named Ysearc)W and YgreetingsW and
earc) (i%% ta1e -ou to )ttp;FF%oca%)ost;8989Fe=amp%esF5spFinde=,)tm%
and greetings (i%% redirect to t)e same page ()ere -ou (ere t)ere,
26
R.V.College of Engineering Dept. of MCA
?( 0r"te a JAVA Ser2#et Pro-ram to "m!#eme)t &e&&"o)& 5U&")- %TTP Se&&"o) I)ter3ace7(
T)e ser#%et container uses t)is interface to create a session $et(een an .TTP c%ient and an .TTP
ser#er, T)e session persists for a specified time period2 across more t)an one connection or page
re&uest from t)e user, A session usua%%- corresponds to one user2 ()o ma- #isit a site man-
times, T)e ser#er can maintain a session in man- (a-s suc) as using coo1ies or re(riting U4Ls,
T)is interface a%%o(s ser#%ets to
Vie( and manipu%ate information a$out a session2 suc) as t)e session identifier2 creation
time2 and %ast accessed time
"ind o$5ects to sessions2 a%%o(ing user information to persist across mu%tip%e user
connections
Metho$&
B$5ect -etAttr"b+te'tring name+4eturns t)e o$5ect $ound (it) t)e specified name in t)is
session2 or nu%% if no o$5ect is $ound under t)e name,
Enumeration -etAttr"b+teName&'+ 4eturns an Enumeration of tring o$5ects containing t)e
names of a%% t)e o$5ects $ound to t)is session,
%ong -etCreat"o)T"me'+ 4eturns t)e time ()en t)is session (as created2 measured in
mi%%iseconds since midnig)t Januar- 12 1639 D/T,
tring -etI$'+ 4eturns a string containing t)e uni&ue identifier assigned to t)is session,
%ong -etLa&tAcce&&e$T"me'+ 4eturns t)e %ast time t)e c%ient sent a re&uest associated (it) t)is
session2 as t)e num$er of mi%%iseconds since midnig)t Januar- 12 1639 D/T2 and mar1ed $- t)e
time t)e container recei#ed t)e re&uest,
int -etMa@I)act"2eI)ter2a#'+4eturns t)e ma=imum time inter#a%2 in seconds2 t)at t)e ser#%et
container (i%% 1eep t)is session open $et(een c%ient accesses, er#%et7onte=t
-etSer2#etCo)te@t'+ 4eturns t)e er#%et7onte=t to ()ic) t)is session $e%ongs,
.ttpession7onte=t -etSe&&"o)Co)te@t'+ ,e!recate$( As of Version 2.1, this method is
deprecated and has no replacement. t will be removed in a future version of the !ava "ervlet
A#.
"&Ne6'+ 4eturns true if t)e c%ient does not -et 1no( a$out t)e session or if t)e c%ient c)ooses not
to 5oin t)e session,
#oid &etAttr"b+te'tring name2 B$5ect #a%ue+ "inds an o$5ect to t)is session2 using t)e name
specified,
#oid &etMa@I)act"2eI)ter2a#'int inter#a%+ pecifies t)e time2 in seconds2 $et(een c%ient re&uests
$efore t)e ser#%et container (i%% in#a%idate t)is session,
23
R.V.College of Engineering Dept. of MCA
Pro-ram;
import 5a#a,io,PrintWriterI
import 5a#a,io,IBE=ceptionI
import 5a#a,uti%,!ateI
import 5a#a=,ser#%et,er#%etE=ceptionI
import 5a#a=,ser#%et,)ttp,.ttper#%etI
import 5a#a=,ser#%et,)ttp,.ttper#%et4e&uestI
import 5a#a=,ser#%et,)ttp,.ttper#%et4esponseI
import 5a#a=,ser#%et,)ttp,.ttpessionI
pu$%ic c%ass essionTrac1er e=tends .ttper#%et
J pu$%ic #oid doDet'.ttper#%et4e&uest re&2 .ttper#%et4esponse
res+t)ro(s er#%etE=ception2 IBE=ception
J res,set7ontentT-pe'Lte=tF)tm%L+I
PrintWriter out K res,getWriter'+I
.ttpession session K re&,getession'true+I
Integer count K 'Integer+ session,getAttri$ute'LcountL+I
if 'count KK nu%%+ J count K ne( Integer'1+IN
e%se Jcount K ne( Integer'count,intVa%ue'+ O 1+I N
session,setAttri$ute'LcountL2 count+I
out,print%n'L:)tm%<:)ead<:tit%e<essionnoop:Ftit%e<:F)ead<L+I
out,print%n'L:$od-<:)1<ession !etai%s:F)1<L+I
out,print%n'LUouE#e #isited t)is page L O count O
''count,intVa%ue'+KK 1+ M L time,L ; L times,L+ O L:$rF<L+I
out,print%n'L:)3<!etai%s of t)is session;:F)3<L+I
out,print%n'Lession id; L O session,getId'+ O L:$rF<L+I
out,print%n'L*e( session; L O session,is*e('+ O L:$rF<L+I
out,print%n'LTimeout; L O session,get/a=Inacti#eInter#a%'+ O
L:$rF<L+I
out,print%n'L7reation time; L O ne(
!ate'session,get7reationTime'++ O L:$rF<L+I
out,print%n'LLast access time; L O ne(
!ate'session,getLastAccessedTime'++ O L:$rF<L+I
out,print%n'L:F$od-<:F)tm%<L+I
28
R.V.College of Engineering Dept. of MCA
N
N
Te&t ,ata;
)ttp;FF%oca%)ost;8989Fe=amp%esFessionTrac1er
refres) t)e page Z -ou s)ou%d see t)at t)e counter (i%% $e incremented and (i%% s)o( t)e
num$er of times t)e page is #isited ,
26
R.V.College of Engineering Dept. of MCA
A a( 0r"te a JAVA JSP Pro-ram to !r")t 10 e2e) a)$ 10 o$$ )+mber(
I) JSP ta-& ca) be $e2"$e$ ")to 4 $"33ere)t t!e&( The&e are;
1( ,"rect"2e&
In t)e directi#es (e can import pac1ages2 define error )and%ing pages or t)e session
information of t)e JP page,
:[R page optiona% attri$ute ,,, [<
2( ,ec#arat"o)&
T)is tag is used for defining t)e functions and #aria$%es to $e used in t)e JP,
:[X [<
<( Scr"!#et&
In t)is tag (e can insert an- amount of #a%id 5a#a code and t)ese codes are p%aced in
\$sp"ervice met)od $- t)e JP engine,
:[ [<

4( E@!re&&"o)&
We can use t)is tag to output an- data on t)e generated page, T)ese data are
automatica%%- con#erted to string and printed on t)e output stream,
BCD CE
Pro-ram;
E2e)O$$(*&!
:)tm%<
:)ead<
:tit%e<cript%et for E#en odd nos print:Ftit%e<
:F)ead<
:$od-<
:)1<19 E#en and 19 odd num$ers:F)1<
:[
out,print'L:$<19 E#en num$ers starting from 1 are:F<:$r<L+I
for 'int iK1Ii :K 29I iOO+J
if'i[2KK9 +
J
out,print'L:$r<:$< L O i O L:F$<L+I
N
N
out,print'L:$r<:$r<:$< 19 Bdd *os starting from 1are :F$<:$r<L+I
for 'int iK1Ii :K 29I iOO+J
if'i[2XK9 +
J
out,print'L:$r<:$< L O i O L:F$<L+I
N
N
39
R.V.College of Engineering Dept. of MCA
[<
:F$od-<
:F)tm%<
Te&t ,ata;
cop- t)e E#enBdd,5sp fi%e to YFusrFs)areFtomcat6@e=amp%esFe=amp%esF5spW director- 2 and t)en
from t)e $ro(ser gi#e t)e fo%%o(ing re&uest
)ttp;FF%oca%)ost;8989Fe=amp%esF5spFE#enBdd,5sp
-ou (i%% see t)e output as 19 E#en and 19 odd num$ers ' T)e out put (i%% $e not as $e%o(2 t)e
num$ers (i%% $e disp%a-ed one $e%o( t)e ot)er 2 for simp%icit- i )a#e p%aced t)e num$ers one
$eside
t)e ot)er (it) a ta$ space+
19 E#en num$ers starting from 1 are
2 4 6 8 19 12 14 16 18 29
19 Bdd *um$ers starting from 1 are
1 3 0 3 6 11 13 10 13 16

31
R.V.College of Engineering Dept. of MCA
A b( 0r"te a JAVA JSP Pro-ram to "m!#eme)t 2er"3"cat"o) o3 a !art"c+#ar +&er #o-") a)$
$"&!#a a 6e#come !a-e(
:5sp;inc%ude< ; to inc%ude pages at re&uest time 2 JP content cannot affect main page; on%-
output of inc%uded JP page is used
:[Rinc%ude< ; 't)e inc%ude directi#e+ to inc%ude fi%es at page trans%ation time2 To reuse JP
content in mu%tip%e pages2 ()ere JP content affects main page
4e&uest!ispatc)er ,for(ardFinc%ude ; Is used ()en (e (ant to for(ard re&uest from ser#er
to ser#er t)ere is no c%ient interaction,
response,send4edirect'+ ; In t)is case c%ient is in#o%#ed2 first re&uest is for(arded to c%ient
and t)en ne( re&uest is generated from c%ient side, In t)is case .eader #a%ue is set $- ser#er
to te%% t)e c%ient $ro(ser to generate ne( re&uest,
Pro-ram;
")$e@3or6ar$(htm#
:)tm%<
:)ead<
:meta )ttp@e&ui#KL7ontent@T-peL contentKLte=tF)tm%Ic)arsetKUT>@8L<
:tit%e<JP Page:Ftit%e<
:F)ead<
:$od-<:)1<.e%%o Users:F)1<
:form met)odKLpostL actionKLfor(ard,5spL<
:p<p%ease enter -our username;
:input t-peKLte=tL nameKLusernameL<
:$r<and pass(ord;
:input t-peKLpass(ordL nameKLpass(ordL<
:Fp<
:p<:input t-peKLsu$mitL #a%ueKL%oginL<:Fp<
:Fform<
:F$od-<
:F)tm%<
3or6ar$(*&!
:[
if 're&uest,getParameter'LusernameL+,e&ua%s'L4ic)ardL++J
if're&uest,getParameter'Lpass(ordL+,e&ua%s'L/ta%%manL++ J
[<
:5sp;for(ard pageKLfor(ard2,5spL F<
:[ N [<
:[ Ne%se J [<
:[R inc%ude fi%eKLinde=for(ard,)tm%L [<
:[ N [<
3or6ar$2(*&!
:)tm%<
32
R.V.College of Engineering Dept. of MCA
:)ead<
:tit%e<:Ftit%e<
:meta )ttp@e&ui#KL7ontent@T-peL contentKLte=tF)tm%Ic)arsetKUT>@8L<
:F)ead<
:$od-<
:)1<>or(ard action test ;Login uccessfu%:F)1<
:[K re&uest,getParameter'LusernameL+ [<
:F$od-<
:F)tm%<
Te&t ,ata;
a#e a%% t)e fi%es in a director- ' i )a#e used Y 13$W+ and t)en
cop- t)at director- to FusrFs)areFtomcat6@e=amp%esFe=amp%esF5sp
director-2
tart tomcat ser#er2 re&uest as $e%o(
)ttp;FF%oca%)ost;8989Fe=amp%esF5spF13$Finde=for(ard,)tm%
on successfu%% %ogin from t)e 5sp fi%e $e%o(
)ttp;FF%oca%)ost;8989Fe=amp%esF5spF13$Ffor(ard,5sp
-ou (i%% get a (e%come message (it) t)e username ,
33
R.V.College of Engineering Dept. of MCA
6, 0r"te a JAVA JSP Pro-ram to -et &t+$e)t ")3ormat"o) thro+-h a %TML a)$ create a
JAVA 1ea) C#a&&> !o!+#ate 1ea) a)$ $"&!#a the &ame ")3ormat"o) thro+-h a)other
JSP(
A Ja#a$ean is 5ust a 5a#a c%ass (it) t)e fo%%o(ing re&uirements,
It )as a pu$%ic no@args constructor
It )as EsetE and EgetE met)ods for its properties,
It ma- )a#e an- genera% functions,
If re&uired it must $e eria%iAa$%e,
.o(e#er2 It is not necessar- a%(a-s t)at a $ean s)ou%d )a#e properties, If t)ere are no properties2
(e need not pro#ide EsetE ] EgetE met)ods eit)er, ' E#en t)e no@args constructor is pro#ided $- t)e
compi%er $- defau%tX+ If t)e $ean uses %i$rar- c%asses a%one2 it is automatica%%- seria%iAa$%e,
In t)at case2 it $ecomes 5ust a c%ass for encapsu%ating some functiona%it- 'ie+ b+&")e&& #o-"c,
uc) a $ean 2 ma- or ma- not )a#e a #isua% representation
Ja#a "eans are reusa$%e components, T)e- are used to separate "usiness %ogic from t)e
Presentation %ogic, Interna%%-2 a $ean is 5ust an instance of a c%ass,
JPMs pro#ide t)ree $asic tags for (or1ing (it) "eans,
B*&!;+&e1ea) "$D:bean name: c#a&&D:bea) c#a&&: &co!e D :!a-e F re4+e&t F &e&&"o) F
a!!#"cat"o) :GE
$ean name K t)e name t)at refers to t)e $ean,
"ean c%ass K name of t)e 5a#a c%ass t)at defines t)e $ean,
B*&!;&etPro!ert )ame D :"$: !ro!ert D :&omePro!ert: 2a#+e D :&omeVa#+e: GE
id K t)e name of t)e $ean as specified in t)e use"ean tag,
propert- K name of t)e propert- to $e passed to t)e $ean,
#a%ue K #a%ue of t)at particu%ar propert- ,
Pro-ram;
pac1age $eansI
pu$%ic c%ass tudent
J
pu$%ic tring nameI
pu$%ic int usnI
pu$%ic tring deparmentI
pu$%ic #oid setname'tring e+
Jname K eIN
34
R.V.College of Engineering Dept. of MCA
pu$%ic tring getname'+
Jreturn nameIN
pu$%ic #oid setusn'int u+
JusnKuIN
pu$%ic tring getusn'+
Jreturn usnIN
pu$%ic #oid setdepartment'tring d+
Jdepartment K dIN
pu$%ic tring getdepartment'+
Jreturn departmentIN
N
Te&t ,ata;
*ote; "efore compi%ing create a director- ca%%ed Y$eansW in
FusrFs)areFtomcat6@e=amp%esFe=amp%esFWE"@I*>Fc%asses so t)at after
compi%ation t)e tudent,c%ass fi%e )as to p%ace t)ere
St+$I)3o(htm#
:)tm%<
:)ead<:tit%e< emp%o-ee information :Ftit%e<:F)ead<
:$od-<
:form action KLfirst,5spL met)od K LpostL<
U* ; :input t-pe K Lte=tL name K LusnLF<:$r<
*ame ; :input t-pe K Lte=tL name KLnameLF<:$r<
!epartment; :input t-pe K Lte=tL name KLdepartmentLF<:$r<
:input t-pe KLsu$mitL #a%ue KLs)o(LF<
:Fform<
:F$od-<
:F)tm%<
3"r&t(*&!
:)tm%<
:$od-<
:5sp;use"ean idKWstuW scopeKLre&uestL c%assKL$eans,tudentLF<
:5sp;setPropert- nameKLstuL propert-KLHLF<
30
R.V.College of Engineering Dept. of MCA
:5sp;for(ard pageKLdisp%a-,5spLF<
:F$od-<
:F)tm%<

$"&!#a(*&!
:)tm%<
:$od-<
:5sp;use"ean idKLstuL scopeKLre&uestL c%assKL$eans,tudentLF<
Emp *ame :5sp;getPropert- nameKLstuL propert-KLnameLF<:$r<
Emp U* :5sp;getPropert- nameKLstuL propert-KLusnLF<:$r<
Emp !epartment :[out,print'stu,getdepartment'++I[<
:F$od-<
:F)tm%<
Te&t ,ata;
after cop-ting t)e Emp%o-ee,c%ass fi%e in
FusrFs)areFtomcat6@e=amp%esFe=amp%esFWE"@I*>Fc%assesF$eansF
director-
p%ace t)e rest of t)e fi%es 'EmpInfo,)tm%2first,5sp and
disp%a-,5sp+ in t)e director-
FusrFs)areFtomcat6@=amp%esFe=amp%esF5sp
t)en if tomcat is running access t)e fi%e
)ttp;FF%oca%)ost;8989Fe=amp%esF5spFtudentinfo,)tm%
-ou (i%% $e propmpted to enter t)e detai%s of tudent
after c%ic1ing on su$mit $utton -ou (i%% see t)e ouput as
*ame a
U* 1
!epartment /7A
htt!;GG#oca#ho&t;A0A0Ge@am!#e&G*&!G3"r&t(*&! ,
36
R.V.College of Engineering Dept. of MCA
10( 0r"te a JAVA JSP Pro-ram 6h"ch +&e& B*&!;!#+-")E ta- to r+) a a!!#et(
T)e :5sp;p%ugin< is used to disp%a- an o$5ect2 especia%%- an app%et or a "ean on t)e c%ient
$ro(ser, W)en t)e Jsp fi%e is trans%ated and compi%ed2 t)e :5sp;p%ugin< is rep%aced $- eit)er an
:o$5ect< or :em$ed< e%ement2 it is $ased on t)e $ro(ser #ersion,
ome of t)e attri$utes of :5sp; p%ugin< are defined $e%o(;
t-pe K L$ean ^app%etL ;@ T)is t-pe of o$5ect (i%% $e e=ecuted $- t)e p%ug@in, It must $e eit)er $ean
or an app%et,
code K L7%ass>i%e*ameL ;@ It is t)e name of t)e 5a#a c%ass fi%e ()ic) (i%% $e e=ecuted $- t)e
p%ug@in, T)e use ,c%ass e=tension is a must,
code$ase K L7%ass>i%e!irector-*ameL ;@ It is t)e name of t)e director- t)at contains t)e 5a#a
c%ass fi%e2 t)at (i%% $e e=ecuted $- t)e p%ug@in,
S)ta@; B*&!; !#+-") t!e D Hbea) Fa!!#etH co$e D HC#a&&F"#eNameH co$e1a&e D
HC#a&&F"#e,"rectorNameH
Pro-ram;
import 5a#a,a(t,HI
import 5a#a,app%et,HI
a!!#et(*a2a
pu$%ic c%ass app%et e=tends App%et
J
int =1K92 -1K1992 =22 -2I
pu$%ic #oid init'+
J
set"ac1ground ' 7o%or,red +I
N
pu$%ic #oid paint'Drap)ics g+
J

if'=1 < 399+
=1K9I
g,fi%%B#a%'=12 -12 392 39+I
=1OOI
tr-J
T)read,s%eep'199+I
N catc)'E=ception e+JN
33
R.V.College of Engineering Dept. of MCA
repaint'+I
N
N
:)tm%<
:tit%e< P%ugin e=amp%e :Ftit%e<
:$od- $gco%orKL()iteL<
:)3< App%et ; :F)3<
:5sp;p%ugin t-peKLapp%etL codeKLapp%et,c%assL code$aseKLapp%etL (idt)KL399L )eig)tKL499L <
:5sp;fa%%$ac1<
P%ugin tag B"JE7T or E/"E! not supported $- $ro(ser,
:F5sp;fa%%$ac1<
:F5sp;p%ugin<
:p<
:)4<
:font co%orKred<
Jsp p%ugin e=amp%e
:Ffont<
:F)4<
:F$od-<
:F)tm%<
Te&t ,ata;
)ttp;FF%oca%)ost;8989Fe=amp%esF%a$Fapp%et5sp,5sp

38
R.V.College of Engineering Dept. of MCA
11(0r"te a JAVA JSP Pro-ram 6h"ch "m!#eme)t& )e&te$ ta-& a)$ a#&o +&e&
Ta-S+!!ort C#a&&(
JP 7ustom Tags ;
Pro#ide a mec)anism to a We$ programmer to reuse and encapsu%ate comp%e= recurring
code in a JP app%ication,
Pro#ide simp%icit- and reusa$i%it- of Ja#a code,
Ena$%e -ou to perform #arious functions2 suc) as;
1( Accessing a%% imp%icit #aria$%es of a JP page2 suc) as re&uest2 response2 in2 and out,
2( /odif-ing t)e response generated $- a ca%%ing JP page,
<( Initia%iAing and instantiating a Ja#a"ean component,
T-pes of 7ustom Tags
T)e #arious t-pes of custom tags t)at -ou can de#e%op in JP are ;
Empt- tags; 4efer to t)e custom tags t)at do not )a#e an- attri$ute or $od-, T)e
fo%%o(ing code snippet s)o(s an empt- custom tag;
:td;(e%come F<
Tags (it) attri$utes; 4efer to custom tags for ()ic) -ou can define attri$utes to
customiAe t)e $e)a#ior of t)e custom tag, T)e fo%%o(ing code snippet s)o(s a custom tag
(it) an attri$ute co%or;
:td; (e%come co%orKM$%ueM<:Ftd;(e%come<
Tags (it) a $od-; 4efer to t)e custom tag (it)in ()ic) -ou can define nested custom
tags2 scripting e%ements2 actions2 .T/L te=t2 and JP directi#es, T)e fo%%o(ing code
snippet s)o(s a custom tag t)at contains a JP scripting e%ement as its $od-;
Pro-ram;
ta-&+!!ort(*&!

:[R tag%i$ uriKLFWE"@I*>Ft%dFtest,t%dL prefi=KLcustomL[<
:custom;parent countr-KLIndiaL<
:custom;c)i%d countr-KLIndiaL<I am in india:Fcustom;c)i%d<
:custom;c)i%d countr-KLUL<I am in U:Fcustom;c)i%d<
:custom;c)i%d countr-KLU?L<I am in U?:Fcustom;c)i%d<
:Fcustom;parent<

te&t(t#$ 's)ou%d $e p%aced in Fapac)e@tomcat@6,9,32F(e$appsFe=amp%esFWE"@I*>Ft%d+
:M=m% #ersionKL1,9L encodingKLIB@8806@1L M<
:tag%i$ =m%nsKL)ttp;FF(((,5a#a,sun,comF=m%FnsF52eeL
=m%ns;=siKL)ttp;FF(((,(3,orgF2991FC/Lc)ema@instanceL
36
R.V.College of Engineering Dept. of MCA
=si;sc)emaLocationKL)ttp;FF5a#a,sun,comF=m%FnsF52eeF(e$@ 5sptag%i$rar-\2\9,=sdL
#ersionKL2,9L<
:t%i$#ersion<1,2:Ft%i$#ersion<
:tag<
:name<parent:Fname<
:tagc%ass<tag,ParentTag.and%er:Ftagc%ass<
:$od-content<5sp:F$od-content<
:attri$ute<
:name<countr-:Fname<
:re&uired<true:Fre&uired<
:Fattri$ute<
:Ftag<
:tag<
:name<c)i%d:Fname<
:tagc%ass<tag,7)i%dTag.and%er:Ftagc%ass<
:$od-content<5sp:F$od-content<
:attri$ute<
:name<countr-:Fname<
:re&uired<true:Fre&uired<
:Fattri$ute<
:Ftag<
:Ftag%i$<
Ch"#$Ta-%a)$#er(*a2a 's)ou%d $e p%aced in Fapac)e@tomcat@6,9,32 F(e$apps F e=amp%esFWE"@
I*>Fc%assesFtag 2 ()ere tag is a pac1age+
pac1age tagI
import 5a#a=,ser#%et,5sp,JspE=ceptionI
import 5a#a=,ser#%et,5sp,tage=t,TagI
import 5a#a=,ser#%et,5sp,tage=t,TagupportI
pu$%ic c%ass 7)i%dTag.and%er e=tends Tagupport J

pu$%ic Tag parentI
pri#ate tring countr-I
pu$%ic int dotartTag'+ t)ro(s JspE=ception J
ParentTag.and%er parentTag K 'ParentTag.and%er+ parentI
if 'get7ountr-'+,e&ua%s'parentTag,get7ountr-'+++ J
return EVAL\"B!U\I*7LU!EI
N
return ?IP\"B!UI
N
pu$%ic #oid setParent'Tag parent+ J
t)is,parent K parentI
N
pu$%ic tring get7ountr-'+ J
return countr-I
49
R.V.College of Engineering Dept. of MCA
N
pu$%ic #oid set7ountr-'tring countr-+ J
t)is,countr- K countr-I
N

N
Pare)tTa-%a)$#er(*a2a 's)ou%d $e p%aced in Fapac)e@tomcat@6,9,32 F(e$apps F
e=amp%esFWE"@I*>Fc%assesFtag 2 ()ere tag is a pac1age+
pac1age tagI
import 5a#a=,ser#%et,5sp,JspE=ceptionI
import 5a#a=,ser#%et,5sp,tage=t,TagupportI

pu$%ic c%ass ParentTag.and%er e=tends Tagupport J
pri#ate tring countr-I
pu$%ic int dotartTag'+ t)ro(s JspE=ception J
return EVAL\"B!U\I*7LU!EI
N
pu$%ic tring get7ountr-'+ J
return countr-I
N
pu$%ic #oid set7ountr-'tring countr-+ J
t)is,countr- K countr-I
N
N
Te&t ,ata;
)ttp;FF%oca%)ost;8989Fe=amp%esF%a$Ftagsupport,5sp
I am in india
41
R.V.College of Engineering Dept. of MCA
12(A) EJ1 a!!#"cat"o) that $emo)&trate& Se&&"o) 1ea)(
A &e&&"o) bea) encapsu%ates $usiness %ogic t)at can $e in#o1ed programmatica%%- $- a c%ient
o#er %oca%2 remote2 or (e$ ser#ice c%ient #ie(s, To access an app%ication t)at is dep%o-ed on t)e
ser#er2 t)e c%ient in#o1es t)e session $eanVs met)ods, T)e session $ean performs (or1 for its
c%ient2 s)ie%ding it from comp%e=it- $- e=ecuting $usiness tas1s inside t)e ser#er,
A session $ean is not persistent, 'T)at is2 its data is not sa#ed to a data$ase,+
T!e& o3 Se&&"o) 1ea)&
ession $eans are of t)ree t-pes; statefu%2 state%ess2 and sing%eton,
State3+# Se&&"o) 1ea)&
T)e state of an o$5ect consists of t)e #a%ues of its instance #aria$%es, In a &tate3+# &e&&"o) bea)2
t)e instance #aria$%es represent t)e state of a uni&ue c%ientF$ean session, "ecause t)e c%ient
interacts 'Yta%1sW+ (it) its $ean2 t)is state is often ca%%ed t)e co)2er&at"o)a# &tate,
As its name suggests2 a session $ean is simi%ar to an interacti#e session, A session $ean is not
s)aredI it can )a#e on%- one c%ient2 in t)e same (a- t)at an interacti#e session can )a#e on%- one
user, W)en t)e c%ient terminates2 its session $ean appears to terminate and is no %onger
associated (it) t)e c%ient,
T)e state is retained for t)e duration of t)e c%ientF$ean session, If t)e c%ient remo#es t)e $ean2 t)e
session ends and t)e state disappears, T)is transient nature of t)e state is not a pro$%em2 )o(e#er2
$ecause ()en t)e con#ersation $et(een t)e c%ient and t)e $ean ends2 t)ere is no need to retain
t)e state,
State#e&& Se&&"o) 1ea)&
A &tate#e&& &e&&"o) bea) does not maintain a con#ersationa% state (it) t)e c%ient, W)en a c%ient
in#o1es t)e met)ods of a state%ess $ean2 t)e $eanVs instance #aria$%es ma- contain a state specific
to t)at c%ient $ut on%- for t)e duration of t)e in#ocation, W)en t)e met)od is finis)ed2 t)e c%ient@
specific state s)ou%d not $e retained, 7%ients ma-2 )o(e#er2 c)ange t)e state of instance #aria$%es
in poo%ed state%ess $eans2 and t)is state is )e%d o#er to t)e ne=t in#ocation of t)e poo%ed state%ess
$ean, E=cept during met)od in#ocation2 a%% instances of a state%ess $ean are e&ui#a%ent2 a%%o(ing
t)e EJ" container to assign an instance to an- c%ient, T)at is2 t)e state of a state%ess session $ean
s)ou%d app%- across a%% c%ients,
"ecause t)e- can support mu%tip%e c%ients2 state%ess session $eans can offer $etter sca%a$i%it- for
app%ications t)at re&uire %arge num$ers of c%ients, T-pica%%-2 an app%ication re&uires fe(er
state%ess session $eans t)an statefu% session $eans to support t)e same num$er of c%ients,
A state%ess session $ean can imp%ement a (e$ ser#ice2 $ut a statefu% session $ean cannot,
0he) to U&e Se&&"o) 1ea)&
tatefu% session $eans are appropriate if an- of t)e fo%%o(ing conditions are true,
T)e $eanVs state represents t)e interaction $et(een t)e $ean and a specific c%ient,
42
R.V.College of Engineering Dept. of MCA
T)e $ean needs to )o%d information a$out t)e c%ient across met)od in#ocations,
T)e $ean mediates $et(een t)e c%ient and t)e ot)er components of t)e app%ication2
presenting a simp%ified #ie( to t)e c%ient,
"e)ind t)e scenes2 t)e $ean manages t)e (or1 f%o( of se#era% enterprise $eans,
To impro#e performance2 -ou mig)t c)oose a state%ess session $ean if it )as an- of t)ese traits,
T)e $eanVs state )as no data for a specific c%ient,
In a sing%e met)od in#ocation2 t)e $ean performs a generic tas1 for a%% c%ients, >or
e=amp%e2 -ou mig)t use a state%ess session $ean to send an emai% t)at confirms an on%ine
order,
T)e $ean imp%ements a (e$ ser#ice,
Pro-ram;
Te&tEJ11ea)(*a2a 5Se&&"o) 1ea)7
pac1age state%essI
import 5a#a=,e5$,tate%essI
FHH
H
H Raut)or )aris)
HF
Rtate%ess
pu$%ic c%ass TestEJ""ean imp%ements TestEJ"4emote2 TestEJ"Loca% J
pu$%ic tring get/essage'+ J
return L)e%%oLI
N
pu$%ic dou$%e add'dou$%e a2 dou$%e $+ J
return 'aO$+I
N
pu$%ic dou$%e su$'dou$%e a2 dou$%e $+ J
return 'a@$+I
N
pu$%ic dou$%e mu%ti'dou$%e a2 dou$%e $+ J
return 'aH$+I
N

N
Te&tEJ1Loca#(*a2a 5Loca# I)ter3ace o3 the &e&&"o) bea)7
43
R.V.College of Engineering Dept. of MCA
pac1age state%essI
import 5a#a=,e5$,Loca%I
FHH
H
H Raut)or )aris)
HF
RLoca%
pu$%ic interface TestEJ"Loca% J
tring get/essage'+I
dou$%e add'dou$%e a2 dou$%e $+I
dou$%e su$'dou$%e a2 dou$%e $+I
dou$%e mu%ti'dou$%e a2 dou$%e $+I

N
Te&tEJ1Loca#(*a2a 5Remote I)ter3ace o3 the &e&&"o) bea)7
pac1age state%essI
import 5a#a=,e5$,4emoteI
FHH
H
H Raut)or )aris)
HF
R4emote
pu$%ic interface TestEJ"4emote J
tring get/essage'+I
dou$%e add'dou$%e a2 dou$%e $+I
dou$%e su$'dou$%e a2 dou$%e $+I
dou$%e mu%ti'dou$%e a2 dou$%e $+I

N
Te&tSer2#et(*a2a 5Ser2#et7
pac1age ser#%etsI
import 5a#a,io,IBE=ceptionI
import 5a#a,io,PrintWriterI
import 5a#a=,e5$,EJ"I
import 5a#a=,ser#%et,er#%etE=ceptionI
import 5a#a=,ser#%et,)ttp,.ttper#%etI
44
R.V.College of Engineering Dept. of MCA
import 5a#a=,ser#%et,)ttp,.ttper#%et4e&uestI
import 5a#a=,ser#%et,)ttp,.ttper#%et4esponseI
import state%ess,TestEJ"4emoteI
FHH
H
H Raut)or )aris)
HF
pu$%ic c%ass Tester#%et e=tends .ttper#%et J
REJ"
pri#ate TestEJ"4emote testEJ""eanI
protected #oid process4e&uest'.ttper#%et4e&uest re&uest2 .ttper#%et4esponse response+
t)ro(s er#%etE=ception2 IBE=ception J
response,set7ontentT-pe'Lte=tF)tm%Ic)arsetKUT>@8L+I
PrintWriter out K response,getWriter'+I
tr- J
dou$%e resu%tK 9,9I
tring s1 K re&uest,getParameter'Lnum1L+I
tring s2 K re&uest,getParameter'Lnum2L+I
tring s3 K re&uest,getParameter'Lgroup1L+I
if's3,e&ua%s'LaddL++
J
resu%t K testEJ""ean,add'!ou$%e,#a%ueBf's1+2!ou$%e,#a%ueBf's2++I
N
if's3,e&ua%s'Lmu%tiL++
J
resu%t K testEJ""ean,mu%ti'!ou$%e,#a%ueBf's1+2!ou$%e,#a%ueBf's2++I
N
if's3,e&ua%s'Lsu$L++
J
resu%t K testEJ""ean,su$'!ou$%e,#a%ueBf's1+2!ou$%e,#a%ueBf's2++I
N
out,print%n'L:)tm%<L+I
out,print%n'L:)ead<L+I
out,print%n'L:tit%e<er#%et Tester#%et:Ftit%e<L+I
out,print%n'L:F)ead<L+I
out,print%n'L:$od-<L+I
out,print%n'L4esu%t KL O resu%t+I
out,print%n'L:)1<er#%et Tester#%et at L O re&uest,get7onte=tPat) '+ O L:F)1<L+I
out,print%n'L:F$od-<L+I
out,print%n'L:F)tm%<L+I

N fina%%- J
out,c%ose'+I
N
40
R.V.College of Engineering Dept. of MCA
N
RB#erride
protected #oid doDet'.ttper#%et4e&uest re&uest2 .ttper#%et4esponse response+
t)ro(s er#%etE=ception2 IBE=ception J
process4e&uest're&uest2 response+I
N
RB#erride
protected #oid doPost'.ttper#%et4e&uest re&uest2 .ttper#%et4esponse response+
t)ro(s er#%etE=ception2 IBE=ception J
process4e&uest're&uest2 response+I
N
RB#erride
pu$%ic tring geter#%etInfo'+ J
return L)ort descriptionLI
NFF :Feditor@fo%d<
N
")$e@(*&!
:[@@
!ocument ; inde=
7reated on ; 16 Jan2 29122 19;06;03 A/
Aut)or ; )aris)
@@[<
:[Rpage contentT-peKLte=tF)tm%L pageEncodingKLUT>@8L[<
:X!B7TUPE .T/L PU"LI7 L@FFW37FF!T! .T/L 4,91 Transitiona%FFE*L
L)ttp;FF(((,(3,orgFT4F)tm%4F%oose,dtdL<
:)tm%<
:)ead<
:meta )ttp@e&ui#KL7ontent@T-peL contentKLte=tF)tm%I c)arsetKUT>@8L<
:tit%e<JP Page:Ftit%e<
:F)ead<
:$od- $gco%orKLpin1L<
:)1<7a%cu%ator:F)1<
:)r<
:form actionKLTester#%etL<
:p<Enter first #a%ue;
:input t-peKLte=tL nameKLnum1L siAeKL20L<:Fp<
:$r<
:p<Enter second #a%ue;
46
R.V.College of Engineering Dept. of MCA
:input t-peKLte=tL nameKLnum2L siAeKL20L<:Fp<
:$r< :$<ec%ect -our c)oice;:F$<:$r<
:input t-peKLradioL nameKLgroup1L #a%ue KLaddL<Addition:$r<
:input t-peKLradioL nameKLgroup1L #a%ue KLsu$L<u$traction:$r<
:input t-peKLradioL nameKLgroup1L #a%ue KLmu%tiL</u%tip%ication:$r<

:p<
:input t-peKLsu$mitL #a%ueKLu$mitL<
:input t-peKLresetL #a%ueKL4esetL<:Fp<
:Fform<
:F$od-<
:F)tm%<
Te&t ,ata;
7ode is de#e%oped using net$eans 6,3 I!E and dep%o-ed using D%assfis) #2 app%ication ser#er
)ttp;FF%oca%)ost;8989FTest@(arF
7a%cu%ator
Enter first #a%ue;
Enter second #a%ue;
Sec#ect o+r cho"ce;
Addition
u$traction
/u%tip%ication
U"/IT 7LEA4
43
R.V.College of Engineering Dept. of MCA
1< A) EJ1 a!!#"cat"o) that $emo)&trate& E)t"t 1ea)(
A) E)t"t 1ea)
An entit- $ean is an o$5ect representation of persistent data maintained in a permanent data store
suc) as a data$ase, A primar- 1e- identifies eac) instance of an entit- $ean, Entit- $eans are
transactiona% and are reco#era$%e in t)e e#ent of a s-stem cras),
Entit- $eans are representations of e=p%icit data or co%%ections of data2 suc) as a ro( in a
re%ationa% data$ase, Entit- $ean met)ods pro#ide procedures for acting on t)e data representation
of t)e $ean, An entit- $ean is persistent and sur#i#es as %ong as its data remains in t)e data$ase,
A) e)t"t bea) ca) be create$ ") t6o 6a&; $- direct action of t)e c%ient in ()ic) a create%&
met)od is ca%%ed on t)e $eanVs )ome interface2 or $- some ot)er action t)at adds data to t)e
data$ase t)at t)e $ean t-pe represents, In fact2 in an en#ironment (it) %egac- data2 entit- o$5ects
ma- e=ist $efore an EJ" is e#en dep%o-ed,
An entit- $ean can imp%ement eit)er $ean@managed or container@managed persistence, In t)e
case of $ean@managed persistence2 t)e imp%ementer of an entit- $ean stores and retrie#es t)e
information managed $- t)e $ean t)roug) direct data$ase ca%%s, T)e $ean ma- uti%iAe eit)er Ja#a
!ata$ase 7onnecti#it- 'J!"7+ or GL@Ja#a 'GLJ+ for t)is met)od, 'ession $eans ma- a%so
access t)e data t)e- manage using J!"7 or GLJ,+ A disad#antage to t)is approac) is t)at it
ma1es it more difficu%t to adapt $ean@managed persistence to a%ternati#e data sources,
In t)e case of container@managed persistence2 t)e container pro#ider ma- imp%ement access to
t)e data$ase using standard APIs, T)e container pro#ider can offer too%s to map instance
#aria$%es of an entit- $ean to ca%%s to an under%-ing data$ase, T)is approac) ma1es it easier to
use entit- $eans (it) different data$ases,
Pro-ram;
Em!(*a2a 5E)t"t C#a&&7
!ac=a-e &er2erI
import 5a#a,io,eria%iAa$%eI
import 5a#a=,persistence,"asicI
import 5a#a=,persistence,7o%umnI
import 5a#a=,persistence,Entit-I
import 5a#a=,persistence,IdI
import 5a#a=,persistence,*amedGueriesI
import 5a#a=,persistence,*amedGuer-I
import 5a#a=,persistence,Ta$%eI
FHH
H
H Raut)or )aris)
HF
48
R.V.College of Engineering Dept. of MCA
REntit-
RTa$%e'name K LempL+
R*amedGueries'JR*amedGuer-'name K LEmp,findA%%L2 &uer- K LELE7T e >4B/ Emp eL+2
R*amedGuer-'name K LEmp,find"-IdL2 &uer- K LELE7T e >4B/ Emp e W.E4E e,id K
;idL+2 R*amedGuer-'name K LEmp,find"-*ameL2 &uer- K LELE7T e >4B/ Emp e W.E4E
e,name K ;nameL+N+
pu$%ic c%ass Emp imp%ements eria%iAa$%e J
pri#ate static fina% %ong seria%VersionUI! K 1LI
RId
R"asic'optiona% K fa%se+
R7o%umn'name K LI!L+
pri#ate Integer idI
R7o%umn'name K L*ameL+
pri#ate tring nameI
pu$%ic Emp'+ J
N
pu$%ic Emp'Integer id+ J
t)is,id K idI
N
pu$%ic Integer getId'+ J
return idI
N
pu$%ic #oid setId'Integer id+ J
t)is,id K idI
N
pu$%ic tring get*ame'+ J
return nameI
N
pu$%ic #oid set*ame'tring name+ J
t)is,name K nameI
N
RB#erride
pu$%ic int )as)7ode'+ J
int )as) K 9I
)as) OK 'id XK nu%% M id,)as)7ode'+ ; 9+I
return )as)I
N
RB#erride
pu$%ic $oo%ean e&ua%s'B$5ect o$5ect+ J
46
R.V.College of Engineering Dept. of MCA
FF TB!B; Warning @ t)is met)od (onEt (or1 in t)e case t)e id fie%ds are not set
if 'X'o$5ect instanceof Emp++ J
return fa%seI
N
Emp ot)er K 'Emp+ o$5ectI
if ''t)is,id KK nu%% ]] ot)er,id XK nu%%+ ^^ 't)is,id XK nu%% ]] Xt)is,id,e&ua%s'ot)er,id+++ J
return fa%seI
N
return trueI
N
RB#erride
pu$%ic tring totring'+ J
return Lser#er,EmpPidKL O id O LQLI
N
N
E)t"tSe&&"o)1ea)(*a2a 5&e&&"o) bea)7
pac1age ser#erI
import 5a#a=,e5$,tate%essI
import 5a#a=,persistence,Entit-/anagerI
import 5a#a=,persistence,Persistence7onte=tI
FHH
H
H Raut)or )aris)
HF
Rtate%ess
pu$%ic c%ass Entit-ession"ean imp%ements Entit-ession4emote2 Entit-essionLoca% J
RPersistence7onte=t
pri#ate Entit-/anager emI
pu$%ic #oid persist'B$5ect o$5ect+ J
em,persist'o$5ect+I
N
pu$%ic #oid addEmp'int id2 tring name+ J
Emp e K ne( Emp'+I
e,setId'id+I
e,set*ame'name+I
persist'e+I
N
Loca# I)ter3ace 3or E)t"tSe&&"o)1ea)
09
R.V.College of Engineering Dept. of MCA
pac1age ser#erI
import 5a#a=,e5$,Loca%I
FHH
H
H Raut)or )aris)
HF
RLoca%
pu$%ic interface Entit-essionLoca% J
#oid addEmp'int id2 tring name+I

N
Remote I)ter3ace 3or E)t"tSe&&"o)1ea)
pac1age ser#erI
import 5a#a=,e5$,4emoteI
FHH
H
H Raut)or )aris)
HF
R4emote
pu$%ic interface Entit-ession4emote J
#oid addEmp'int id2 tring name+I

N
Ne6Ser2#et(*a2a 5Ser2#et 6h"ch 6"## ")teract 6"th Se&&"o) 1ea)7
pac1age ser#%etsI
import 5a#a,io,IBE=ceptionI
import 5a#a,io,PrintWriterI
import 5a#a=,e5$,EJ"I
import 5a#a=,ser#%et,er#%etE=ceptionI
import 5a#a=,ser#%et,)ttp,.ttper#%etI
import 5a#a=,ser#%et,)ttp,.ttper#%et4e&uestI
import 5a#a=,ser#%et,)ttp,.ttper#%et4esponseI
import ser#er,Entit-ession4emoteI
FHH
H
H Raut)or )aris)
HF
pu$%ic c%ass *e(er#%et e=tends .ttper#%et J
REJ"
01
R.V.College of Engineering Dept. of MCA
pri#ate Entit-ession4emote entit-ession"eanI


protected #oid process4e&uest'.ttper#%et4e&uest re&uest2 .ttper#%et4esponse response+
t)ro(s er#%etE=ception2 IBE=ception J
response,set7ontentT-pe'Lte=tF)tm%Ic)arsetKUT>@8L+I
PrintWriter out K response,getWriter'+I
tr- J
entit-ession"ean,addEmp'Integer,parseInt're&uest,getParameter'LidL++2re&uest,getPara
meter'LnameL++I
out,print%n'L:)tm%<L+I
out,print%n'L:)ead<L+I
out,print%n'L:tit%e<er#%et *e(er#%et:Ftit%e<L+I
out,print%n'L:F)ead<L+I
out,print%n'L:$od-<L+I
out,print%n'L:)1< !ata $ase Updated :F)1<L+I
out,print%n'L:F$od-<L+I
out,print%n'L:F)tm%<L+I

N fina%%- J
out,c%ose'+I
N
N
RB#erride
protected #oid doDet'.ttper#%et4e&uest re&uest2 .ttper#%et4esponse response+
t)ro(s er#%etE=ception2 IBE=ception J
process4e&uest're&uest2 response+I
N
RB#erride
protected #oid doPost'.ttper#%et4e&uest re&uest2 .ttper#%et4esponse response+
t)ro(s er#%etE=ception2 IBE=ception J
process4e&uest're&uest2 response+I
N
RB#erride
pu$%ic tring geter#%etInfo'+ J
return L)ort descriptionLI
NFF :Feditor@fo%d<
N
")$e@(*&!
:[Rpage contentT-peKLte=tF)tm%L pageEncodingKLUT>@8L[<
02
R.V.College of Engineering Dept. of MCA
:X!B7TUPE .T/L PU"LI7 L@FFW37FF!T! .T/L 4,91 Transitiona%FFE*L
L)ttp;FF(((,(3,orgFT4F)tm%4F%oose,dtdL<
:)tm%<
:)ead<
:meta )ttp@e&ui#KL7ontent@T-peL contentKLte=tF)tm%I c)arsetKUT>@8L<
:tit%e<Emp%o-ee !etai%:Ftit%e<
:F)ead<
:$od-<
:form actionKL*e(er#%etL met)odKLgetL<
:)1< er#%et EJ" ession Entit- "ean :F)1<
E/P I! ; :input t-peKLte=tL siAeKL3L nameKLidL < :$r<
E/P *A/E; :input t-peKLte=tL siAeKL10L nameKLnameL< :$r<
:input t-peKLsu$mitL nameKLpostL #a%ueKLpostL<
:input t-peKLresetL nameKLc%earL #a%ueKLc%earL<
:Fform<
:F$od-<
:F)tm%<
Te&t ,ata;
7ode is de#e%oped using net$eans 6,3 I!E and dep%o-ed using D%assfis) #2 app%ication ser#er
)ttp;FF%oca%)ost;8989FEntit-Test@(arF
er#%et EJ" ession Entit- "ean
E/P I! ; 1
E/P *A/E; )aris)
SU1MIT CLEAR
03
R.V.College of Engineering Dept. of MCA
14( A) EJ1 a!!#"cat"o) that $emo)&trate& M,1(
A message@dri#en $ean is an enterprise $ean t)at a%%o(s Ja#a EE app%ications to process
messages as-nc)ronous%-, T)is t-pe of $ean norma%%- acts as a J/ message %istener2 ()ic) is
simi%ar to an e#ent %istener $ut recei#es J/ messages instead of e#ents, T)e messages can $e
sent $- an- Ja#a EE component 'an app%ication c%ient2 anot)er enterprise $ean2 or a (e$
component+ or $- a J/ app%ication or s-stem t)at does not use Ja#a EE tec)no%og-, /essage@
dri#en $eans can process J/ messages or ot)er 1inds of messages,
0hat Ma=e& Me&&a-eJ,r"2e) 1ea)& ,"33ere)t 3rom Se&&"o) 1ea)&:
T)e most #isi$%e difference $et(een message@dri#en $eans and session $eans is t)at c%ients do
not access message@dri#en $eans t)roug) interfaces, Interfaces are descri$ed in t)e section
Accessing Enterprise "eans, Un%i1e a session $ean2 a message@dri#en $ean )as on%- a $ean c%ass,
In se#era% respects2 a message@dri#en $ean resem$%es a state%ess session $ean,
A message@dri#en $eanVs instances retain no data or con#ersationa% state for a specific
c%ient,
A%% instances of a message@dri#en $ean are e&ui#a%ent2 a%%o(ing t)e EJ" container to
assign a message to an- message@dri#en $ean instance, T)e container can poo% t)ese
instances to a%%o( streams of messages to $e processed concurrent%-,
A sing%e message@dri#en $ean can process messages from mu%tip%e c%ients,
T)e instance #aria$%es of t)e message@dri#en $ean instance can contain some state across t)e
)and%ing of c%ient messages2 suc) as a J/ API connection2 an open data$ase connection2 or an
o$5ect reference to an enterprise $ean o$5ect,
7%ient components do not %ocate message@dri#en $eans and in#o1e met)ods direct%- on t)em,
Instead2 a c%ient accesses a message@dri#en $ean t)roug)2 for e=amp%e2 J/ $- sending messages
to t)e message destination for ()ic) t)e message@dri#en $ean c%ass is t)e /essageListener, Uou
assign a message@dri#en $eanVs destination during dep%o-ment $- using D%ass>is) er#er
resources,
/essage@dri#en $eans )a#e t)e fo%%o(ing c)aracteristics,
T)e- e=ecute upon receipt of a sing%e c%ient message,
T)e- are in#o1ed as-nc)ronous%-,
T)e- are re%ati#e%- s)ort@%i#ed,
T)e- do not represent direct%- s)ared data in t)e data$ase2 $ut t)e- can access and update
t)is data,
T)e- can $e transaction@a(are,
T)e- are state%ess,
W)en a message arri#es2 t)e container ca%%s t)e message@dri#en $eanVs on/essage met)od to
process t)e message, T)e on/essage met)od norma%%- casts t)e message to one of t)e fi#e J/
message t-pes and )and%es it in accordance (it) t)e app%icationVs $usiness %ogic, T)e on/essage
04
R.V.College of Engineering Dept. of MCA
met)od can ca%% )e%per met)ods or can in#o1e a session $ean to process t)e information in t)e
message or to store it in a data$ase,
A message can $e de%i#ered to a message@dri#en $ean (it)in a transaction conte=t2 so a%%
operations (it)in t)e on/essage met)od are part of a sing%e transaction, If message processing
is ro%%ed $ac12 t)e message (i%% $e rede%i#ered,
0he) to U&e Me&&a-eJ,r"2e) 1ea)&
ession $eans a%%o( -ou to send J/ messages and to recei#e t)em s-nc)ronous%- $ut not
as-nc)ronous%-, To a#oid t-ing up ser#er resources2 do not to use $%oc1ing s-nc)ronous recei#es
in a ser#er@side componentI in genera%2 J/ messages s)ou%d not $e sent or recei#ed
s-nc)ronous%-, To recei#e messages as-nc)ronous%-2 use a message@dri#en $ean,
In t)is e=amp%e2 (e are going to imp%ement a /essage@dri#en $ean app%ication named
Lma&&a-eL t)at )as t)e fo%%o(ing components;
A c%ient app%ication t)at sends se#era% messages to a &ueue; Me&&a-eC#"e)t
A message@dri#en $ean t)at as-nc)ronous%- recei#es and processes t)e messages t)at are
sent to t)e &ueue; Me&&a-e1ea)
Pro-ram;
pac1age md$I
import 5a#a=,5ms,HI
import 5a#a=,naming,HI
import 5a#a,te=t,HI
import 5a#a=,annotation,HI
R4esource'mapped*ameKL5msFGueueL+
c%ass /essage7onnJ
pri#ate static Gueue &ueue K nu%%I
Gueue7onnection>actor- factor- K nu%%I
Gueue7onnection connection K nu%%I
Gueueender sender K nu%%I
Gueueession session K nu%%I
pu$%ic /essage7onn'+J
tr- J
FFc%ient creates t)e connection2 session2 and message sender;
connection K factor-,createGueue7onnection'+I
00
R.V.College of Engineering Dept. of MCA
session K connection,createGueueession'fa%se2
Gueueession,AUTB\A7?*BWLE!DE+I
sender K session,createender'&ueue+I
FFcreate and set a message to send
Te=t/essage msg K session,createTe=t/essage'+I
for 'int i K 9I i : 0I iOO+ J
msg,setTe=t'LT)is is m- sent message L O 'i O 1++I
FFfina%%- c%ient sends messages
FFas-nc)ronous%- to t)e &ueue
sender,send'msg+I
N
-stem,out,print%n'Lending messageL+I
session,c%ose '+I
N catc) 'E=ception e+ J
e,printtac1Trace '+I
N
N
N

pu$%ic c%ass /essage7%ientJ
pu$%ic static #oid main'tringPQ args+J
/essage7onn msgcon K ne( /essage7onn'+I
N
N
For 0ebJc#"e)t;
In a We$@c%ient app%ication L5msFGueueL and 7onnection>actor-L argument are used in t)e J*!I
%oo1up, "ot) are %ogica% J*!I names2 and use t)e out$ound connecti#it- pro#ided $- t)e J/
resource adapter, /a1e t)e J*!I %oo1up to use a We$ er#ice s)o(n as,
Initia%7onte=t ct= K ne( Initia%7onte=t'+I
&ueue K 'Gueue+ ct=,%oo1up'L5msFGueueL+I
Gueue7onnection>actor- factor- K
'Gueue7onnection>actor-+ ct=,%oo1up'L7onnection>actor-L+I
connection K factor-,createGueue7onnection'+I
06
R.V.College of Engineering Dept. of MCA
session K cnn,createGueueession'fa%se2
Gueueession,AUTB\A7?*BWLE!DE+I
The Me&&a-e1ea) c#a&& $emo)&trate& the 3o##o6")- re4+"reme)t& to "t& "m!#eme)tat"o);
pac1age md$I
import 5a#a=,e5$,HI
import 5a#a=,e5$,/essage!ri#enI
import 5a#a=,5ms,/essageI
import 5a#a=,5ms,/essageListenerI
import 5a#a=,5ms,B$5ect/essageI
import 5a#a,te=t,HI
import 5a#a=,naming,HI
import 5a#a,uti%,%ogging,LoggerI
R/essage!ri#en'mapped*ameKL5msFGueueL+
pu$%ic c%ass /essage"ean imp%ements /essageListener J
R4esource
pri#ate /essage!ri#en7onte=t mdcI
pri#ate static fina% Logger %oggerI

pu$%ic #oid on/essage'/essage msg+ J
Te=t/essage tmsg K nu%%I
tr- J
tmsg K 'Te=t/essage+ msgI
%ogger,info'L/EADE "EA*; /essage recei#ed; L O tmsg,getTe=t' ++I
-stem,out,print%n 'LT)e on/essage'+ is ca%%edL+I
N catc) 'J/E=ception e+ J
e,printtac1Trace' +I
mdc,set4o%%$ac1Bn%-' +I
N
catc) 'T)ro(a$%e t)+ J
t),printtac1Trace'+I
N
N
pu$%ic #oid e5$4emo#e' +t)ro(s EJ"E=ceptionJ
%oger,fine'Le5$4emo#e'+L+I
N
N
Te&t $ata;
In t)e ser#er %og fi%e2 t)e fo%%o(ing %ines s)ou%d $e disp%a-ed2 (rapped in %ogging information;
03
R.V.College of Engineering Dept. of MCA
/EADE "EA*; /essage recei#ed; T)is is m- sent message 1
/EADE "EA*; /essage recei#ed; T)is is m- sent message2
/EADE "EA*; /essage recei#ed; T)is is m- sent message 3
/EADE "EA*; /essage recei#ed; T)is is m- sent message 4
08
R.V.College of Engineering Dept. of MCA
06
Viva questions & extra
programs
R.V.College of Engineering Dept. of MCA
VIVAJ 8UESTIONS
1, Use of 7%ass,for*ame
2, Use of !ri#er /anager,getconnection
3, 4esu%t set
4, Use of ne=t ' + met)od in resu%t set
0, Prepared tatement
6, E=p%ain i, er#%ets Life 7-c%e '(it) diagram+ ii, er#%ets API
3, E=p%ain doDet2 doPost t-pes in er#%et2 (rite a program to imp%ement doDet or doPost
using ser#%ets
8, E=p%ain different t-pes of JP Tags
6, List t)e t)ree 1inds of EJ" c%asses,
19, E=p%ain t)e t(o important interfaces of EJ",
11, E=p%ain t)e creation of ession Ja#a "ean,
12, E=p%ain t)e Entit- Ja#a "ean
13, E=p%ain t)e creation of /essage@!ri#en "ean,
14, List some of t)e app%ications of 5a#a $eans,
10, Di#e an e=amp%e to Imp%ementing E#ent .and%ing (it) Adapter c%ass
16, E=p%ain t)e met)ods2 re$ind'+ and %oo1up'+ in *aming c%assM
13, .o( do -ou pass data 'inc%uding Ja#a"eans+ to a JP from a ser#%etM
18, W)at is er#%et c)ainingM
16, W)at is t)e %ife c-c%e of a ser#%etM
29, W)at is t)e difference $et(een doPost and doDet met)odsM
21, W)at are t)e steps in#o%#ed for ma1ing a connection (it) a data$ase or )o( do -ou
connect to a data$aseM
22, W)at are dri#ers a#ai%a$%e for data$ase connectionsM
23, W)at are t)e t)ree $ean timesM
24, W)at are t)e fi#e features of a Ja#a"eanM
20, W)at is a propert-M
26, W)at is t)e E#entTarget!ia%og in t)e "ean"o=M
23, W)ere do t)e 5ar fi%es for $eans go in t)e "ean"o=M
28, .o( do (e compi%e and e=ecute a Ja#a c%ass t)at resides in a pac1ageM
26, W)at goes in a manifest fi%e for a Ja#a"eanM
39, W)at is t)e ad#antage of denorma%iAationM
31, Is t)e J!"7@B!"7 "ridge mu%ti@t)readedM
32, W)at is t)e fastest t-pe of J!"7 dri#erM
33, W)at are t)e different J!" dri#ers a#ai%a$%eM
34, W)at is 7onnection poo%ingM
30, W)at is 7onnectionM
36, W)at is J!"7M
33, W)at are t)e steps re&uired to e=ecute a &uer- in J!"7M
38, W)at is J!"7 !ri#er M
36, W)at is t)e ser#%etM
49, W)at are t)e JP atrri$utesM
69
R.V.College of Engineering Dept. of MCA
41, W)at is t)e need of super,init'config+ in ser#%etsM
42, .o( to 1no( ()et)er (e )a#e to use 5sp or ser#%et in our pro5ectM
43, 7an (e ca%% destro-'+ met)od on ser#%ets from ser#ice met)odM
44, W)at is t)e er#%et InterfaceM
40, W)at is t)e difference $et(een Denericer#%et and .ttper#%etM
46, .o( (e can c)ec1 in particu%ar page t)e session (i%% $e a%i#e or notM
43, W)at is t)e importance of dep%o-ment descriptor in ser#%etM
48, W)en (e increase t)e $uffer siAe in our pro5ect using page directi#e attri$ute _$ufferV
()at c)anges (e o$ser#eM
46, W)at is t)e difference $et(een er#et7onfig and er#%et7onte=t,,M
09, W)en a ser#%et accepts a ca%% from a c%ient2 it recei#es t(o o$5ects, W)at are t)e-M
01, W)at are t)e differences $et(een DET and PBT ser#ice met)odsM
02, In ()ic) conditions (e )a#e to use t)e er#%et7onte=tM
03, W)at met)ods (i%% $e ca%%ed in ()ic) orderM''i,e+ser#ice'+2doget'+2dopost'++
E@tra Pro-ram&
1, 111Write a JP Program W)ic) Aut)enticate T)e user from !ata"ase and 4edirect to anot)er
JP page
2, Write A JP program to demonstrate !ec%arati#e tag
3, Write A JP program t)at 7a%%s er#%et to perform 7a%cu%ator operations'addition2 su$2
mu%tip%ication+ for t(o argument send $- JP
4, Write an EJ" app%ication t)at demonstrates ession "ean for s)opping cart,
61
R.V.College of Engineering Dept. of MCA
J2EE Lab Cc#e For the &eme&ter
S+b*ect Co$e; 10MCA46 I(A Mar=&; K0
%o+r&G0ee=; < E@am %o+r&; 0<
Tota# %o+r&; 42 E@am Mar=&; K0
Lab
Cc#e
Pro-ram )+mber 6"th the 4+e&t"o)
1
a(Write a JAVA Program to insert data into tudent !ATA "AE and retrie#e info
$ased on particu%ar &ueries '&ueries can $e gi#en ()ic) co#ers a%% t)e topics of 2nd
U*IT+,
2
a(Write a JAVA er#%et Program to imp%ement a d-namic .T/L using er#%et
'user name and pass(ord s)ou%d $e accepted using .T/L and disp%a-ed using a
er#%et+,
b(Write a JAVA er#%et Program to !o(n%oad a fi%e and disp%a- it on t)e screen 'A
%in1 )as to $e pro#ided in .T/L2 ()en t)e %in1 is c%ic1ed corresponding fi%e )as to
$e disp%a-ed on creen+
3
a(Write a JAVA er#%et Program to imp%ement 4e&uest!ispatc)er o$5ect 'use
inc%ude'+ and for(ard'+ met)ods+,
b(Write a JAVA er#%et Program to imp%ement and demonstrate get'+ and Post
met)ods'Using .TTP er#%et 7%ass+,
4
a(Write a JAVA er#%et Program to imp%ement send4edirect'+ met)od'using .TTP
er#%et 7%ass+,
b(Write a JAVA er#%et Program to imp%ement sessions 'Using .TTP ession
Interface+,
0
a( Write a JAVA JP Program to print 19 e#en and 19 odd num$er,
b, Write a JAVA JP Program to imp%ement #erification of a particu%ar user %ogin
and disp%a- a (e%come page,
6
a(Write a JAVA JP Program to get student information t)roug) a .T/L and
create a JAVA "ean 7%ass2 popu%ate "ean and disp%a- t)e same information t)roug)
anot)er JP,
b(Write a JAVA JP Program ()ic) uses :5sp;p%ugin< tag to run a app%et,
3
a(Write a JAVA JP Program ()ic) imp%ements nested tags and a%so uses
Tagupport 7%ass,
8
a(An EJ" app%ication t)at demonstrates ession "ean,
6
a(An EJ" app%ication t)at demonstrates Entit- "ean,
19
a(An EJ" app%ication t)at demonstrates /!",
62
R.V.College of Engineering Dept. of MCA
Proce$+re& 3or recor$ 0r"t")-
Left ide of t)e record;
1( teps for t)e program,
2( Butput of t)e program,
<( Verified !ata )eet to $e stuc1ed
4ig)t ide of t)e record;
1( Program source code s)ou%d $e (ritten,
Lab e2a#+at"o) !roce$+re
La$ e=ercise e#a%uation
Program E=ecution Z 3 /ar1s
Vi#a Z 3 /ar1s
Interna% E#a%uation La$
29 /ar1s @ La$ 4ecords
39 /ar1s @ Interna%s
'/an5u D+ '.aris) D,/+ !irector /7A
>acu%t- ec _AV; >acu%t- ec _"V;
>e$ 2912 >e$ 2912
63

You might also like