Web Component Sample Questions

Embed Size (px)

Citation preview

  • 8/15/2019 Web Component Sample Questions

    1/75

     

    Questions 1. Click the Exhibit button.

    Given the HTML form:

    1.

    .

    +. ,rice:

    .

    0.

  • 8/15/2019 Web Component Sample Questions

    2/75

    8. 9(ro!uct.(rice % ($r$m.i;

    C.

    2ns=er: C

    Ex(l$n$tion:

    Questions . ou nee! to cre$te $ ?$v$8e$n ob'ect th$t is use! onl" =ithin the current @A,

     ($Be. @t must *3T be $ccessible to $n" other ($Be inclu!inB those th$t this ($Be miBht

    im(ort. 4hich ?A, st$n!$r! $ction < .in $ccom(lish this Bo$l6

    2.

    E.

    4hich is true6

    2. the ($Be =ill inclu!e the out(ut f$lse

    8. the ($Be =ill inclu!e the out(ut

    C. the ($Be =ill re(ort th$t the (ro(ert" ro$ste! !oes not exist

    . the ($Be =ill re(ort th$t the s"nt$x of the use8e$n t$B is incorrect

    E. the ($Be =ill re(ort th$t the s"nt$x of the Bet,ro(ert" t$B ls incorrect

    2ns=er: E

    Ex(l$n$tion:

    Questions ). 2 !evelo(er chooses to $voi! usinB sinBieThre$!Mo!el but =$nts to ensure

    th$t !$t$ @fF u(!$te! in $ thre$! s$fe m$nner.

    4hich t=o c$n su((ort this !esiBn Bo$l6 Choose t=o

  • 8/15/2019 Web Component Sample Questions

    3/75

    2. Atore the !$t$ in $ loc$l v$ri$ble.

    8. Atore the !$t$ in $n inst$nce v$ri$ble.

    C. Atore the !$t$ in the Htt(session ob'ect.

    . Atore the !$t$ in the s$rvletContext ob'ect.

    E. Atore the !$t$ in the AervletIeuest ob'ect.

    2ns=er: 25E

    Ex(l$n$tion:

    Questions +. ou h$ve $ use in "our =eb $((lic$tion th$t $!!s sever$l sessionsco(e!

    $ttributes. 2t the en! of the use c$se5 one of these ob'ects5 the m$n$Be $ttribute5 is remove!

    $n! then it nee!s to !eci!e =hich of the other sessionsco(e! $ttributes to remove.

    Ho= c$n this Bo$l be $ccom(lishe!6

    2. The ob'ect of the m$n$Ber $ttribute shoul! im(lement the Htt(Aession8in!inBListener

    $n! it shoul! c$ll the remove2ttribute metho! on the $((ro(ri$te session $ttributes.

    8. The ob'ect of the m$n$Ber $ttribute shoul! im(lement the Htt(AessionListen$r $n! itshoul! c$ll the remove2ttribute metho! on the $((ro(ri$te session $ttributes.

    C. The ob'ect of the m$n$Ber $ttribute shoul! im(lement the Htt(Aession8in!inBListener

    rin! it shoul! c$ll the !elete2ttribute metho! on the $((ro(ri$te session $ttributes.

    . The ob'ect of the m$n$Ber $ttribute shoul! im(lement the Htt(sessionListener $n! it

    shoul! c$ll the !elete2ttribute metho! on the $((ro(ri$te session $ttributes.

    2ns=er: 2

    Ex(l$n$tion:

    Questions -. The Aue$k" 8e$ns @nc. sho((inB $((lic$tion =$s initi$ll" !evelo(e! for $

    non!istribute! environment. The com($n" recentl" (urch$se! the 2cme 2((lic$tionAerver5 =hich su((orts !istribute! Htt(session ob'ects. 4hen !e(lo"inB the $((lic$tion to

    the server5 the !o(lo"er m$rks it $s !istribut$ble in the =eb $((lic$tion !e(lo"ment

    !escri(tor to t$ke $!v$nt$Be of this fe$ture. Given this scen$rio5 =hich t=o must be true6

    Choose t=o

    2. The ?EE =eb cont$iner must su((ort miBr$tion of ob'ects th$t im(lement seri$liN$ble.

    8. The ?EE =eb cont$iner must use the n$tive ?OM Aeri$liN$tion mech$nism for

    !istributinB Htt(Aes$ion ob'ects.

    C. 2s (er the s(ecific$tion5 the ?EE =eb cont$iner ensures th$t !istribute! Htt(s$ssion

    ob'ects =ill be store! in $ !$t$b$se.

    . AtorinB references to Enter(rise ?$v$8e$ns com(onents in the Htt(Aession ob'ect miBht

     *3T su((orte! b" ?EE =eb cont$in.

    2ns=er: 25

    Ex(l$n$tion:

    Questions . Given $n Htt(AervletIeuest reuest $n! $n htt(AervletIes(onse res(onse:

    )1. Htt(Aession session % nullF

  • 8/15/2019 Web Component Sample Questions

    4/75

    ). / / insert co!e here

    )#. if session % % null

    )). / / !o somethinB if session !oes not exist

    )+. ; else

    )-. / / !o somethinB if session exists

    ). ;

    To im(lement the !esiBn intent5 =hich st$tement must be inserte! $t line )6

    2. session % res(onse.BetAession F

    8. session % reuest.BetAession F

    C. session % reuest.BetAession trueF

    . session % reuest.BetAession f$lseF

    E. session % reuest.BetAession &'sessioni!&F

    2ns=er:

    Ex(l$n$tion:

    Questions 0. Psers of "our =eb $((lic$tion h$ve reueste! th$t the" shoul! be $ble to set

    the !ur$tion of their sessions. Ao for ex$m(le5 one user miBht =$nt $ =eb$(( to st$"

    connecte! for $n hour r$ther th$n the =eb$((Ds !ef$ult of fifteen minutesF $nother user

    miBht =$nt to st$" connecte! for $ =hole !$".

    urthermore5 "ou h$ve $ s(eci$l loBin servlet th$t (erforms user $uthentic$tion $n!

    retrieves the ob'ect from the !$t$b$se. ou =$nt to $uBment this co!e to set u( the userDs

    s(ecifie! session !ur$tion.

    4hich co!e sni((et in the loBin servlet =ill $ccom(lish this Bo$l6

    2. Pser user % / / retrieves the user ob'ects ob'ect from the !$t$b$se

    session.setur$tion@nterv$l user.BetAessionur$tionF8. Pser user % / / retrieves the Pser ob'ects from the !$t$b$se session.set@n$ctive@nterv$l

    user.BetAessionur$tionF

    C. Pser user % / / retrieves the user ob'ects ob'ect from the !$t$b$se

    session.set@n$ctive@nterv$l user.Bet.Aessionur$tionF

    . Pser user % / / retrieves the user ob'ects ob'ect from the !$t$b$se session.setur$tion

    user.BetAessionur$tionF

    E. Pser user % / / retrieves the user ob'ects ob'ect from the !$t$b$se

    session.setM$x@n$ctive@nterv$l user.BetAessionur$tionF

    . Pser user % / / retrieves the user ob'ects ob'ect from the !$t$b$se

    session.setM$xur$tion@nterv$l user.BetAessionur$tionF

    2ns=er: E

    Ex(l$n$tion:

    Questions . 4hich interf$ce must $ cl$ss im(lement so th$t inst$nces of the cl$ss $re

    notifie! $fter $n" ob'ect $!!e! to $ session6

    2. '$v$x.servlet.htt(.Htt(AessionListener 

  • 8/15/2019 Web Component Sample Questions

    5/75

    8. '$v$x.servlet.htt(.Htt(AessionO$lueListener 

    C. '$v$x.servlet.htt(.Htt(Aession8in!inBListener 

    . '$v$x.servlet.htt(.Htt(Aession2ttributeListener 

    2ns=er:

    Ex(l$n$tion:

    Questions 1. 4hich st$tement is true $bout =eb cont$iner session m$n$Bement6

    2. 2ccess to sessionsco(e! $ttributes is Bu$r$ntee! to be thre$!s$fe b" the =eb cont$iner.

    8. To $ctiv$te PIL re=ritinB5 the !evelo(er must use the

    Htt(AervletIes(onse.setPILIe=ritinB metho!.

    C. @f the =eb $((lic$tion uses HTT,A5 then the =eb cont$iner m$" use the !$t$ on the

    HTT,A reuest stre$m to i!entif" the client.

    . The ?AEAA@3*@ cookie is store! (erm$nentl" on the client so th$t $ user m$" return to

    the =eb $((lic$tion $n! the =eb cont$iner =ill re'oin th$t session.

    2ns=er: CEx(l$n$tion:

    Questions 11. A method call inside your servlet has thrown an IOException

    resulting from a lost network connection to a necessary resource. The servlet

    has determined that it will e unale to operate successfully fen few minutes!

    ut expects to e ale to resume operation after that period. "ow should this

    situation handled#

    A. The servlet should re$throw the exception to the we container.

    %. The servlet should throw a servletException to the we container.

    &. The servlet should throw an unavailaleException to the we container.

    '. The servlet should redirect to an error page that reports the exceptionmessage.

    E. The servlet should retry the re(uest until the method returns successfully.

    Answer) &

    Explanation)

    Questions 1*. 'uring initiali+ation! a servlet ,nds that the dataase connection

    it re(uires is unavailale. As the system designer! you know that the dataase

    start up completes several minutes after the we$ container initiali+es the

    servlet. "ow should this e handled#

    A. -etry the connection until it is successful! then allow the init/ method tocomplete.

    %. Throw a 0ervletException

    &. Throw the IOException

    '. Throw an navailaleException

    Answer) '

    Explanation)

  • 8/15/2019 Web Component Sample Questions

    6/75

    Questions 12. A servlet wishes to indicate that it is unale to initiali+e at the

    present time! ut that the initiali+ation might succeed at some future time.

    3hich is true#

    A. This cannot e expressed. A servlet either initiali+es correctly or fails.

    %. This expression is not necessary. If a servlet fails to initiali+e! the container

    will try again later each time a re(uest is received that attempts to invoke thatservlet.

    &. The servlet should delay until it is ready to complete initiali+ation

    successfully.

    '. The servlet should throw an navailaleException

    E. The servlet should throw a servletException

    Answer) E

    Explanation)

    Questions 14. 5ou are implementing a model component. 5ou reali+e that an

    IOException might arise if you lose connection to the dataase. "ow should you

    address this#

    A. Implement multipathing to provide redundant connectivity to the dataase!

    therey avoiding that risk of connection failure.

    %. 6rovide an error handler page! and use the page directive in the invoking I06

    to redirect to that page if the error arises.

    &. se the 70T8 9c)catch: tag to take control if the exception arises.

    '. 0urround the prolem area with a try;catch lock and implement appropriate

    recovery or fallack ehavior.

    Answer) &

    Explanation)

    Questions 1

  • 8/15/2019 Web Component Sample Questions

    7/75

    &. Access is to e denied independent of authentication state and identity.

    '. Only authenticated users are to e permitted.

    E. Access is to e permitted independent of authentication state and identity.

    Answer) %!&

    Explanation)

    Questions 1F. 3hich of the following annotations relate to security in a servlet#

    i/ B3e0ecurity

    ii/ B-olesAllowed

    iii/ B3e&onstraint

    iv/ B"ttp&onstraint

    v/ B0ervletsecurity

    A. i/ only

    %. i/ and iii/

    &. iv/ and v/

    '. iii/ and v/

    E. ii/ and iv/

    Answer) &

    Explanation)

    Questions 1G. 3hich element of a we application deployment descriptor

    9we$resource$collection: element is used to specify a "TT6 method to which

    the corresponding 9security$constraint: will not apply#

    A. 9exclude$http$method:

    %. 9neglect$http$method:

    &. 9http$method$omission:

    '. 9http$method$excluded:E. 9exceptional$http$method:

    Answer) &

    Explanation)

    Questions 1H. 3hich two statements are true aout the security$related tags in

    a valid 7ava EE deployment descriptor# &hoose two/

    A. Every 9security$constraint: tag must have at least one 9http$method: tag.

    %. A 9security$constraint: tag can have many 9we$resource$collection: tags.

    &. A given 9auth$constraint: tag can apply to only one 9we$resource$

    collection: tag.'. A given 9we$resource$collection: tag can contain from +ero to many 9url$

    pattern: tags.

    E. It is possile to construct a valid 9security$constraint: tag such that! for a

    given resource user roles can access that resource.

    Answer) %!E

    Explanation)

  • 8/15/2019 Web Component Sample Questions

    8/75

    Questions *. A cookie may e set to e an "ttpOnly cookie. 0etting a cookie

    to e "ttpOnly results in &hoose two/

    A. &lient to not expose the cookie to client side scripting code

    %. 'oes not work with https protocol

    &. prevent certain types of cross$site scripting attacks

    '. There is no such thing as an "ttpOnly cookieAnswer) A!&

    Explanation)

    Questions *1. A popular AJax framework and its companion widget lirary

    contain several hundreds of ,les of diKerent types .Js! .ess! .html/. 5our

    company has mandated that all its we applications use only speci,c versions

    of this framework approved y IT and repackaged internally as Jar ,les.

    Lurthermore! we applications should only include the entire Jar! without

    susetting or modi,cation.

    3here should the frameworkMs ,les e placed inside a Jar ,le to enale this

    kind of reuse#A. under resources

    %. under =ETA$I?L;resources

    &. under =ETA$I?L;we$contents

    '. under 3E%$I?L;resources

    Answer) %

    Explanation)

    Questions **. 3hich two actions protect a resource ,le from direct "TT6 access

    within a we application# &hoose two/

    A. placing it in the ;secure directory%. placing it in the ;3E%$I?L directory

    &. placing it in the ;=ETA$I?L;secure directory

    '. creating a 9we$resource: element within the deployment descriptor

    E. creating a 9secure$resource: element within the deployment descriptor

    Answer) %!&

    Explanation)

    Questions *2. In which two locations can lirary dependencies e de,ned for a

    we application# &hoose two/

    A. the we application deployment descriptor

    %. the ;=ETA$I?L;dependencies.xml ,le

    &. the ;=ETA$I?L;=A?ILE0T.=L manifest ,le

    '. the ;=ETA$I?L;=A?ILE0T.=L manifest of a 7A- in the we application

    classpath

    Answer) &!'

    Explanation)

  • 8/15/2019 Web Component Sample Questions

    9/75

    Questions *4. The J(ueryN1N2N*.Jar ,le contains the 7Query AJax framework in

    its =ETA$I?L; resources directory. 3here should the Jar ,le e placed inside the

    we application to ensure the resources it contains are accessile y clients#

    A. 3E%$I?L;classes

    %. 3E%$I?L;Jar

    &. 3E%$I?L;li'. 3E% I?L;resources

    Answer) &

    Explanation)

    Questions *! 5 and respectively.

    3hich of the following deployment descriptor! we.xml! snippets correspond to

    the we fragment processing orders of >! 5! #

    i/ 9asolute$ordering:

    9name:>9;name:

    9name:59;name:

    9name:9;name:

    9;asolute$ordering:

    ii/ 9asolute$ordering:

    9name:>9;name:

    9name:59;name:

    9;asolute$ordering:

    iii/ 9asolute$ordering:

    9;others:

    9name:59;name:

    9name:9;name:9;asolute$ordering:

    iv/ 9asolute$ordering:

    9name:>9;name:

    9;others:

    9name:9;name:

    9;asolute$ordering:

    v/ 9asolute$ordering:

    9name:>9;name:

    9name:59;name:

    9;others:9;asolute$ordering:

    A. i/ only

    %. i/ and ii/

    &. i/ and iv/

    '. i/! iii/! iv/ and v/

    Answer) &

    Explanation)

  • 8/15/2019 Web Component Sample Questions

    10/75

    Questions *@. 3hich de,nes the welcome ,les in a we application deployment

    descriptor#

    A. 9;welcome:

    %. 9;welcome$,le$list:

    &. 9;we1come :'. 9;welcome$,le$list:

    E. 9;welcome:

    Answer) %

    Explanation)

    Questions *F. 3hich code snippet speci,es the metadata for a servlet with)

    i/ url mapping D;mytestDM

    ii/ Initial parameter with name DdeugD and value D1DM iii/ 0upport

    asynchronous operation#

    A. pulic class Test0ervlet extends "ttp0ervlet CP

    %. 6ulic class test0ervlet CP

    &. Initparams CBInit6aram name DdeugD! value D1D/ P! supportAsync

    true/ pulic class Test0ervlet extends "ttp0ervlet CP

    '. Initparams CBInit6aram name DdeugD! value D1D/ P!

    async0upported true/ pulic class Test0ervlet extends "ttp0ervlet CP

    E. Initparam B3eInit6aram name DdeugD! value D1D/! supportAsync

    true/ pulic class test0ervlet CP

    Answer) '

    Explanation)

    Questions *G. 3hich annotation speci,es the metadata as a Javax.servlet.http."ttp0ession8istener#

    A. B8istener

    %. B3e8istener

    &. B3e0ession8istener

    '. B"ttp0ession8istener

    Answer) A

    Explanation)

    Questions *H. 5ou are creating a new I06 page and you need to execute some

    code that acts when the$ page is ,rst executed! ut only once. 3hich three arepossile mechanisms for performing this initiali+ation code# &hoose three/

    A. In the init method.

    %. In the JspInit method.

    &. In the constructor of the 706Ms 7ava code.

    '. In a 706 declaration! which includes an initiali+er lock.

    E. In a 706 declaration! which includes a static initiali+er lock.

    Answer) %!'!E

  • 8/15/2019 Web Component Sample Questions

    11/75

    Explanation)

    Questions 2. 5ou are creating a we form with this "T=8)

    11. 9form actionDsendOrder.JspD:

    1*. 9input typeDtextD nameDcredit&ardD:

    12. 9input typeDtextD nameDexpiration'ateD:14. 9input typeDsumitD:

    1

  • 8/15/2019 Web Component Sample Questions

    12/75

    8. @n $ reuest he$!er C. @n the reuest line. @n the reuest PIL2ns=er: 8Ex(l$n$tion:

    Questions #). 4hich ?ATL co!e sni((et c$n be use! to im(ort content from $nother =ebresource62. C. E. @m(ortinB c$nnot be !one in ?ATL. 2 st$n!$r! $ction must be use! inste$!.2ns=er: 2Ex(l$n$tion:

    Questions #+. @n $ 's(centric sho((inB c$rt $((lic$tion c$rt $((lic$tion to move $ clientDshome $!!ress of Customer ob'ect into the shi((inB $!!ress of the or!er ob'ect. The $!!ress!$t$ is store! in $ v$lue ob'ect cl$ss c$lle! 2!!ress =ith (ro(erties for: street $!!ress5 cit"5 (rovince5 countr"5 $n! (ost$l co!e.4hich t=o co!e sni((ets c$n be use! to $ccom(lish this Bo$l62. v$lue%D9client.home2!!ress;D />8. v$lue%D9client.home2!!ress;D />C. E.

  • 8/15/2019 Web Component Sample Questions

    13/75

    Questions #. 4hich ?A, st$n!$r! $ction c$n be use! to im(ort content from $ resourcec$lle! foo.'s(62. 8.

    C. . E. foo.'s(

  • 8/15/2019 Web Component Sample Questions

    14/75

    Ex(l$n$tion:

    Questions #. Given the element from the =eb $((lic$tion !e(lo"ment !escri(tor:

    2ns=er: C

    Ex(l$n$tion:

    Questions ). 2 =eb $((lic$tion $llo=s the HTML title b$nner to be set usinB $ context

    initi$liN$tion ($r$meter c$lle! titlestr.

    4hich t=o (ro(erl" set the title in the scen$rio6 Choose t=o

    2. 9 titlestr;

    8. 9 init($r$m.titlestr;

    C. 9 ($r$m J. titlestr;

    . 9 ($r$mO$lues.titleAtr; E. 9 init,$r$m titleAtrDJ ;

    . 9 servlet,$r$ms.titleAtr;

    G. 9 reuest.Bet &titleAtr& ;

    2ns=er: 85E

    Ex(l$n$tion:

    Questions )1. Given:11. 1+. 4hich three EL ex(ressions5 inserte! $t line 1+5 $re v$li! $n! ev$lu$te to &6 Choosethree2. 9v$ls.;8. 9v$ls &&J ;C. 9v$ls.in!ex;

  • 8/15/2019 Web Component Sample Questions

    15/75

    . 9v$lsin!exJ ;E. 9v$ls; in!exJ. 9v$ls. v$ls.in!ex ;G. 9v$ls v$lsin!ex1JJ ;2ns=er: 855G

    Ex(l$n$tion:

    Questions ). Given:4hich three EL ex(ressions5 inserte! $t line 1-5 $re v$li! $n! ev$lu$te to &!&6 Choosethree

    2. 9m$(.c;8. 9m$(.cJ;C. 9m$(.&c&J;. 9m$(.m$(.b;E. 9m$(.m$(.bJ;. 9m$(. m$(.b;2ns=er: 25C5EEx(l$n$tion:

    Questions )#. 4hich is $ benefit of (recom(ilinB $ ?A, ($Be62. @t $voi!s initi$liN$tion on the first reuest.

    8. @t (rovi!es the $bilit" to !ebuB runtime errors in the $((lic$tion.C. @t (rovi!es better (erform$nce on the first reuest for the ?A, ($Be.. @t $voi!s execution of the U's(Aervice metho! on the first reuest.2ns=er: CEx(l$n$tion:

    Questions )). 2 =eb bro=ser nee! *3T $l=$"s (erform $ com(lete reuest for $ ($rticul$r  ($Be th$t it sus(ects miBht *3T h$ve ch$nBe!. The HTT, s(ecific$tion (rovi!es $mech$nism for the bro=ser to retrieve onl" $ ($rti$l res(onse from the =eb serverF thisres(onse inclu!es inform$tion5 such $s the L$stMo!ifie! !$te but *3T the bo!" of the ($Be. 4hich HTT, metho! =ill the bro=ser use to retrieve such $ ($rti$l res(onse6

    2. GET8. 2AV C. AE*. HE2E. TI2CE. 3,T@3*A2ns=er: Ex(l$n$tion:

  • 8/15/2019 Web Component Sample Questions

    16/75

    Questions )+. 2 Client =$nts to retrieve $ re(resent$tion of $ resource5 for ex$m(le $nHTML ($Be5 $llo=inB $ c$che! version to be returninB b" $n interme!i$r" such $ (rox"server.4hich HTT, metho! shoul! it use6

    2. GET8. ,PTC. ,3AT. ELETE2ns=er: 2Ex(l$n$tion:

    Questions )-. 4hich t=o $re true $bout the ?ATL core iter$tion custom t$Bs6 Choose t=o.

    2. @t m$" iter$te over $rr$"s5 collections5 m$(s5 $n! strinBs.8. The bo!" of the t$B m$" cont$in EL co!e5 but not scri(tinB co!e.C. 4hen loo(inB over collections5 $ loo( st$tus ob'ect m$" be use! in the t$B bo!".. @t m$" iter$te over m$(5 but onl" the ke" of the m$((inB m$" be use! in the t$B bo!".E. 4hen loo(inB over inteBers for ex$m(le beBin% 1D en!% 1D5 $ loo( st$tus ob'ect m$"not be use! in the t$B bo!".2ns=er: 25CEx(l$n$tion:

    Questions ). 2ssume $ ?$v$8e$n com.ex$m(le.Gr$!e!Test8e$n exists $n! h$s t=o$ttributes. The $ttribute n$me of t"(e '$v$.l$nB.strinB $n! the $ttribute score is of t"(e '[email protected] $rr$" of com.ex$m(le.Gr$!e!Test8e$n ob'ects is ex(ose! to the ($Be in $ reuestsco(e! $ttribute c$lle! results. 2!!ition$ll"5 $n em(t" '$v$.util.H$shM$( c$lle! resultM$(is (l$ce! in the ($Be sco(e.2 ?A, ($Be nee!s to $!! the first entr" in results to resultM$(5 storinB the n$me $ttribute ofthe be$n $s the ke" $n! the score $ttribute of the be$n $s the v$lue.4hich co!e sni((et of ?ATL co!e s$tisfies this reuirement62. 9resultM$(resultsJ.n$meJ % resultsJ.score;8. v$lue%&9resultsJ.score;& />C. . v$lue%&9resultsJ.score;& />2ns=er: EEx(l$n$tion:

    Questions )0. or m$n$Be$bilit" (ur(oses5 "ou h$ve been tol! to $!! $ &count& inst$ncev$ri$ble to $ critic$l ?A, ocument so th$t $ ?MR M8e$n c$n tr$ck ho= freuent this ?A,is beinB invoke!. 4hich ?A, co!e sni((et must "ou use to !ecl$re this inst$nce v$ri$ble inthe ?A, ocument62.

  • 8/15/2019 Web Component Sample Questions

    17/75

    C. 2ns=er: 2Ex(l$n$tion:

    Questions ). To t$ke $!v$nt$Be of the c$($bilities of mo!ern bro=sers th$t use =ebst$n!$r!s5 such $s RHTML $n! CAA5 "our =eb $((lic$tion is beinB converte! from sim(le?A, ($Bes to ?A, ocument form$t. Ho=ever5 one of "our ?A,s5/scri(ts/screenunctions.'s(5 Bener$tes $ ?$v$Acri(t file. This file is inclu!e! in sever$l =ebforms to cre$te screens(ecific v$li!$tion functions $n! $re inclu!e! in these ($Bes =ith thefollo=inB st$tement:4hich ?A, co!e sni((et !ecl$res th$t this ?A, ocument is $ ?$v$Acri(t file6

    2.

  • 8/15/2019 Web Component Sample Questions

    18/75

  • 8/15/2019 Web Component Sample Questions

    19/75

  • 8/15/2019 Web Component Sample Questions

    20/75

  • 8/15/2019 Web Component Sample Questions

    21/75

    Ex(l$n$tion:

    Questions -. ou $re buil!inB $ !$tinB service =eb site. ,$rt of the form to submit $

    clientDs (rofile is $ Brou( of r$!io buttons for the (ersonDs hobbies:

    . HikinB

    1. AkinB

    . ACP82

    #. >

    2fter the user submits this form5 $ confirm$tion screen is !is(l$"e! =ith these hobbies

    liste!. 2ssume th$t $n $((lic$tionsco(e! hobbies5 hol!s $ m$( bet=een the hobb"

    enumer$te! t"(e $n! the !is(l$" n$me.

    4hich EL co!e sni((et =ill !is(l$" *th element of the userDs selecte! hobbles6

    2. 9hobbies hobb"Enum*J;

    8. 9hobbies ($r$mO$lues.hobb"Enum*JJ;

    C. 9hobbies ($r$mO$lues X hobb"EnumD X*J. 9hobbies.Bet($r$mO$lues.hobb"Enum*J ;

    E. 9hobbies ($r$mO$lues.hobb"Enum.Bet*J ;

    2ns=er: 8

    Ex(l$n$tion: Questions -1. or =hich three events c$n =eb $((lic$tion event listeners be

    reBistere!6 Choose three.

    2. =hen $ session is cre$te!

    8. $fter $ servlet is !estro"e!

    C. =hen $ session h$s time! out

    . =hen $ cookie h$s been cre$te!

    E. =hen $ servlet h$s for=$r!e! $ reuest. =hen $ session $ttribute v$lue is ch$nBe!

    2ns=er: 25C5

    Ex(l$n$tion:

    Questions -. To $!! $ servlet to $ context th$t h$s not been !ecl$re! either vi$ $nnot$tion

    or vi$ the !escri(tor5 !urinB context initi$liN$tion time the follo=inB 2,@ c$n be use!

    Choose three.

    2. servletContext.$!!Aervlet&m"Aervlet*$me&5 &M"Aervlet&F

    8. Aervlet>BetCl$ss.BetCl$ssLo$!er.BetCl$ssLo$!er.lo$!erCl$ss&M"Aervlet&F

    C. servletContext.$!!Aervletm"AervletF

    . servletContext.$!!Aervlet &m"Aervlet*$me&5 BerCl$ss.BetCl$ssLo$!er.lo$!erCl$ss&m"Aervlet&F

    E. servletContext.$!!Aervlet&m"Aervlet*$me&5 M"AervletF

    2ns=er: 255E

    Ex(l$n$tion:

  • 8/15/2019 Web Component Sample Questions

    22/75

    Questions -#. AervletContextListeners $re invoke! in

    2. I$n!om or!er 

    8. context@niti$liNe! $n! contextestro"e! $re invoke! in the or!er in =hich the" $re

    !ecl$re! in the =eb.xml

    C. context@niti$liNe! metho! $re invoke! in the or!er in =hich the" $re !ecl$re! in the

    =eb.xml $n! the contextestro"e! metho! is invoke! in the reverse or!er in =hich the" $re

    !ecl$re! in the =eb.xml

    . context@niti$liNe! $n! contextestro"e! $re invoke! in the reverse or!er of =hich the"

    $re !ecl$re! in the =eb.xml

    2ns=er: C

    Ex(l$n$tion:

    Questions -). 2 servlet cl$ss is in'ecte! =ith $ ?8C !$t$ source. 2fter in'ection h$s

    occurre!5 the servlet nee!s to cre$te $ c$che out of some of the !$t$ in the !$t$b$se5 so $s to

    im(rove res(onsiveness. 4hich t=o metho!s c$n host the c$che cre$tion co!e6 Chooset=o

    2. Aervlet.init

    8. Aervlet.!estro"

    C. 2 metho! $nnot$te! =ith X@nit

    . 2 metho! $nnot$te! =ith X,ostConstruct

    E. 2 metho! $nnot$te! =ith X,reestro"

    . 2 metho! $nnot$te! =ith XIesource

    2ns=er: 25

    Ex(l$n$tion:

    Questions -+. Oie= the Exhibit.

    4hich t=o technoloBies =oul! be suit$ble for use $s ront Controller elements6 Choose

    t=o

    2. ?A,8. Aervlet

  • 8/15/2019 Web Component Sample Questions

    23/75

    C. ilter . ,3?3E. Custom T$B2ns=er: 258Ex(l$n$tion:

    Questions --. Given:1. #. 9+ Z # @t -;). AreuestAco(eDfooDJJ ne 1 !iv>+. 91 !iv ;4h$t is the result62. true true8. f$lse trueC. f$lse true . true true @nfinit"E. f$lse true @nfinit". 2n exce(tion is thro=nG. Com(il$tion or tr$nsl$tion f$ils2ns=er: EEx(l$n$tion:

    Questions -. Oie= the Exhibit.Given the =eb $((lic$tion !e(lo"ment !escri(tor elements:11. 1. ,$r$m2!!er1#. com.ex$m(le.,$r$m2!!er1). ...#1. #. ,$r$m2!!er##. estin$tion#). ...++. +-. estin$tion+. /!est/estin$tion+0. 4h$t is the result of $ client reuest of the Aource servlet =ith no uer" strinB6

  • 8/15/2019 Web Component Sample Questions

    24/75

    2. The out(ut &filter2!!e! % null& is =ritten to the res(onse stre$m.

    8. The out(ut &filter2!!e! % $!!e!8"ilter& is =ritten to the res(onse stre$m.

    C. 2n exce(tion is thro=n $t runtime =ithin the service metho! of the Aource servlet.

    . 2n exce(tion is thro=n $t runtime =ithin the service metho! of the estin$tion servlet.

    2ns=er: 2

    Ex(l$n$tion:

    Questions -0. ou $re buil!inB $ =eb $((lic$tion =ith $ sche!ulinB com(onent. 3n the ?A,5

    "ou nee! to sho= the current !$te5 the !$te of the (revious =eek5 $n! the !$te of the next=eek.

    To hel( "ou (resent this inform$tion5 "ou h$ve cre$te! the follo=inB EL functions in the !D

    n$mes($ce:

    6 *$me : cur$t$F siBn$ture: '$v$.util.util$te Current$te 6 *$me : cur$t$F siBn$ture:

     '$v$.util.util$te $!!=eek '$v$.util.$te5 int

    6 *$me: !$teAtrinBF siBn$ture: '$v$.util.AtrinB Bet$t$AtrinB '$ve.util.$t$

  • 8/15/2019 Web Component Sample Questions

    25/75

    4hich EL co!e sni((et =ill Bener$te the strinB for the (revious =eek6

    2. 9!:!$teAtrinB$ff4eekcur$te5 1 ;

    8. 9!:!$teAtrinB $!!4eekcur$teJ5 JJ ;

    C. 9!:!$teAtrinB !:$!!4eek!:cur$teJ5 1JJ ;

    . 9!:!$teAtrinB !:$!!4eek!:cur$te5 1 ;

    2ns=er:

    Ex(l$n$tion:

    Questions -. Given $ he$!er in $n

    H. @, reuest:

    RIetries: )

    2 4hich t=o retrieve the v$lue of the he$!er from $ Biven Htt(AervletIeuest reuest6

    Choose t=o

    2. reuestBetHe$!er&RIetries&

    8. reuest.BetlntHe$!er&RIetries&C. reuest.BetIeuestHe$!er&RIetries&

    . reuest.BetHe$!ers&RIetries&.Bet

    E. reuest.BetIeuestHe$!ers&RIetries&.Bet

    2ns=er: 258

    Ex(l$n$tion:

    Questions . Given $n Htt(AervletIeuestreuest $n! Htt(Ies(onseres(onse5 =hich sets $

    cookie &usern$me& =ith the v$lue &'oe& in $ servlet6

    2. reuest.$!!Cookie&usern$me&5 &'oe&

    8. reuest.setCookie&usern$me&5 &'oe&C. res(onse.$!!Cookie&usern$me&5 &'oe&

    . reuest.$!!He$!erne= Cookie&usern$me&5 &'oe&

    E. reuest.$!!Cookiene= Cookie&usern$me&5 &'oe&

    . res(onse.$!!Cookiene= Cookie&usern$me&5 &'oe&

    G. res(onse.$!!He$!erne= Cookie&usern$me&5 &'oe&

    2ns=er:

    Ex(l$n$tion:

    Questions 1. 4hich $nnot$tion en$bles $ servlet to efficientl" (rocess reuests of t"(o

    multi($rt/form!$t$ th$t involve l$rBe files beinB u(lo$!e! b" the client62. X2cce(tMulti($rt8. XMulti,$rtConfiBC. XMulti,$rtorm$t$. X4ebAervlet multi($rt % true2ns=er: 8Ex(l$n$tion:

  • 8/15/2019 Web Component Sample Questions

    26/75

    Questions . 2,@s for !"n$mic$ll" reBisterinB servlets $n! filters c$n be c$lle! $t:2. Context initi$liN$tion time8. 2n" timeC. There is no =$" to !"n$mic$ll" reBister servlets $n! filters. Context !estruction time

    E. @n'ecte! into $ servlet context2ns=er: 2Ex(l$n$tion:

    Questions #. AervletIeBistr$tion."n$mic c$n be use! to confiBure Choose t=o2. ilter m$((inBs8. $!! init ($r$msC. set $s"ncAu((orte! to true. $!! Listeners2ns=er: 258Ex(l$n$tion:

    Questions ). 2 =eb $((lic$tion =$nts to reBister $ ne= servlet $t runtime usinB one of theservletContext.$!!Aervlet metho!s.@n the im(lement$tion of =hich metho! is it leB$l to (erform this o(er$tion62. 2s"ncListner.oncom(lete8. Aervlet.initC. AervletContextListener.context@niti$liNe. AervletreuestListener.context@niti$liNe2ns=er: CEx(l$n$tion:

    Questions +. ou =$nt to cre$te $ filter for "our =eb $((lic$tion $n! "our filter =illim(lement.servlet.ilter.4hich t=o st$tements $re true6 Choose t=o2. our filter cl$ss must im(lement $n init metho! $n! $ !estro" metho!.8. our filter cl$ss must $lso im(lement '$v$x.s$rvl$t.ilterCh$in.C. 4hen "our filter ch$ins to the next filter5 it shoul! ($ss the s$me $rBuments it receive!in its !oilter metho!.. The metho! th$t "our filter invokes on the ob'ect it receive! th$t im(lements '$v$x 6servlet.ilterch$in c$n invoke either $nother filter or $ servlet.E. our filter cl$ss must im(lement $ !oilter metho! th$t t$kes5 $monB other thinBs5 $nHtt(AervletIeuest ob'ect $n! $n Htt(Aervletres(onse ob'ect.2ns=er: 25Ex(l$n$tion:

    Questions -. 4hich three $re true $bout the Htt(AervletIeuest4r$((er cl$ss6 Choosethree.2. The Htt(AervletIeuest4r$((er is $n ex$m(le of the ecor$tor ($ttern.8. The Htt(AervletIeuest4r$((er c$n be use! to exten! the function$lit" of $ servletreuest.

  • 8/15/2019 Web Component Sample Questions

    27/75

    C. 2 subcl$ss of Htt(AervletIeuest4r$((er C2**3T mo!if" the beh$vior of theBetIe$!er metho!.. 2n Htt(AervletIeuest4r$((er m$" be use! onl" b" $ cl$ss im(lement the '$v$x.servlet.ilter interf$ce.E. 2n Htt(AervletIeuest4r$((er C2**3T be use! on the reuest ($sse! to the

    Ieuestis($tcher.interf$ce.. 2n Htt(AervletIeuest4r$((er m$" mo!if" the he$!er of $ reuest =ithin $n ob'ectim(lementinB the '$v$x.servlet.ilter interf$ce.2ns=er: 2585Ex(l$n$tion:

    Questions . Given $ =$r file =ith the follo=inB structure[ 4E8@*/cl$sses/M"servlet.cl$ss[ 4E8@*/lib/=f.'$f4here =f.'$r cont$ins $ v$li! =ebfr$Bment.xml $n! the follo=inB t=o cl$sses:M"ilter1.cl$ss $n! M"iler.cl$ss.The =ebfr$Bment.xml is $s follo=s:The follo=inB $re some co!e sni((ets:4hen one $ccess &/& of the $bove =eb $((lic$tion5 =hich filters =ill be execute!6

    2. *o filters =ill be execute!.

    8. M"ilter1

    C. M"ilter

    . M"ilter1 $n! M"ilter2ns=er: C

    Ex(l$n$tion:

    Questions 0. ou h$ve $ sim(le =(b $((lic$tion th$t h$s $ sinBle ront Controller servlet

    th$t !is($tches to ?A,s Bener$te $ v$riet" of vie=s. Aever$l of these vie=s reuire further

    !$t$b$se (rocessinB to retrieve the necess$r" or!er ob'ect usinB the or!er@ reuest

  • 8/15/2019 Web Component Sample Questions

    28/75

  • 8/15/2019 Web Component Sample Questions

    29/75

    2. 8. 2ns=er: 25C

    Ex(l$n$tion:

    Questions 0. 4hen usinB Aervlet $s"nchronous 2,@ if "ou =$nt to !is($tch the reuest b$ck to $ ($rticul$r url &/url& =ithin the s$me Aervlet Context =hich of the follo=inB 2,@=oul! "ou use62. 2A"ncContext.!is($tchF8. 2s"ncContext.!is($tch&/url&FC. 2s"ncContext.!is($tchservletContext5 &/url&F

  • 8/15/2019 Web Component Sample Questions

    30/75

    . 2s"ncContext.st$rtrunn$bleFE. Ieuestis($tcher.fot=$r!&/url&F. Ieuestis($tcher.for=$r!servletContext5 &/url&FG. Ieuestis($tcher.inclu!e&/url&F2ns=er: C

    Ex(l$n$tion:

    Questions 0#. 4hich !escribes $ triBBer th$t c$uses $ c$ll to $n 2s"ncListener62. Com(letion of (rocessinB8. Iecei(t of $ ne= reuest from the s$me clientC. 2!!ition of $ ne= filter to the (rocessinB stre$m for this reuest. Com(letion of e$ch timer interv$l2ns=er: 8Ex(l$n$tion:

    Questions 0). Iefer to the Exhibit.2 servlet sets $ sessionsco(e! $ttribute (ro!uct =ith $n inst$nce of com.ex$m(le.(ro!uct$n for=$r! to $ ?A,. 4hich t=o out(ut the n$me of the (ro!uct in the res(onse6 Chooset=o

    2.

  • 8/15/2019 Web Component Sample Questions

    31/75

    8. . E.
    1. ,ro!uct ,rice:

  • 8/15/2019 Web Component Sample Questions

    32/75

    2. i!8. n$me

    C. t"(e

    . ($r$m

    E. (ro(ert"

    . re,$r$m

    G. $ttribute

    2ns=er: 855E

    Ex(l$n$tion:

    Questions 0. 2 !evelo(er =$nts to m$ke $ n$me $ttribute $v$il$ble to $ll servlets$ssoci$te! =ith $ ($rticul$r user5 $cross multi(le reuests from th$t user5 from the s$me

     bro=ser inst$nce. 4hich t=o (rovi!e this c$($bilit" from =ithin $ t$B h$n!ler6 Choose

    t=o

    2. ($BeContext.set2ttribute&n$me&5 theO$lueF

    8. ($BeContext.set2ttribute&n$me&5 BetAession F

    C. ($BeContext.BetIeuest.set2ttribute&n$me&5 theO$lueF

  • 8/15/2019 Web Component Sample Questions

    33/75

    . ($BeContext.BetAession.set2ttribute&n$me&5 theO$lueF

    E. ($BeContext.set2ttribute&n$me&5 theO$lue5 ,$BeContext.,2GEUAC3,EF

    . ($BeContext.set2ttribute&n$me&5 theO$lue5 ,$BeContext.AEAA@3*UAC3,EF

    2ns=er: 5

    Ex(l$n$tion:

    Questions 00. Given th$t $ =eb $((lic$tion consists of t=o Htt(Aervlet cl$sses5 Aervlet2

    $n! Aervlet85 $n! the Aerverlet2.service metho!:

    . AtrinB ke" % &com.ex$m(le.!$t$&F

    1. session.set2ttributeke"5 &Hello&F

    . ob'ect v$lue % session.Bet2ttributeke"F

    #.

    2ssume session is $n Htt(Aession5 $n! is not reference! $n"=here else in Aervlet2. 4hich

    t=o ch$nBes5 t$ken toBether5 ensure th$t v$lue is eu$l to &Hello& on line #6 Choose t=o

    2. ensure th$t the Aervlet8.service metho! is s"nchroniNe!8. ensure th$t the Aervlet2.service metho! is s"nchroniNe!

    C. ensure th$t Aervlet8 s"nchroniNes on the session ob'ect =hen settinB session $ttributes

    .

    E.

    2ns=er: C5E

    Ex(l$n$tion:

    Questions 0. Given $n Htt(AervletIeuest reuest:

    . AtrinB i! % reuest.Bet,$r$meter&'sessioni!&F

    #. // insert co!e here). AtrinB n$me % AtrinB session.Bet2ttribute&n$me&

    4hich three c$n be (l$ce! $t line # to retrieve $n existinB Htt(Aession ob'ect6 Choose

    three

    2. Htt(Aession session % reuest.BetAessionF

    8. Htt(Aession session % reuest.BetAessioni!F

    C. Htt(Aession session % reuest.BetAessiontrueF

    . Htt(Aession session % reuest.BetAessionf$lseF

    E. Htt(Aession session % reuest.BetAession&'sessioni!&F

    2ns=er: 25C5

    Ex(l$n$tion:

    Questions . 2s $ convenience fe$ture5 "our =eb ($Bes inclu!e $n 2'$x reuest ever" five

    minutes to $ s(eci$l servlet th$t monitors the $Be of the userDs session. The clientsi!e

    ?$v$Acri(t th$t h$n!les the 2'$x c$llb$ck !is(l$"s $ mess$Be on the screen $s the session

    $Bes. The 2'$x c$ll !oes *3T ($ss $n" cookies5 but it ($sses the session @ in $ reuest

     ($r$meter c$lle! session@

  • 8/15/2019 Web Component Sample Questions

    34/75

    . @n $!!ition5 $ssume th$t "our =eb$(( kee(s $ h$sm$( of session ob'ects b" the @

    . Here is $ ($rti$l im(lement$tion of this servlet:

    1. (ublic cl$ss Aession2BeAervlet exten!s Htt(Aervlet

    11. (ublic voi! serviceHtt(AervletIeuest reuest5 Htt(AervletIes(onse thro=s

    @3Exce(tion

    1. AtrinB session@ % reuest.Bet,$r$meter&session@&F

    1#. Htt(Aession session % BetAessionsession@F

    1). lonB $Be % // "our co!e here

    1+. res(onse.Bet4riter.(rint$BeF

    1-. ;

    ... // more co!e here

    ). ;

    4hich co!e sni((et on line 1)5 =ill !etermine the $Be of the session6

    2. session.BetM$x@n$ctive@nterv$lF

    8. session.BetL$st2ccesse!.BetTime 6 session.BetCre$tionTime.BetTimeFC. session.BetL$st2ccesse!Time.BetTime 6 session.BetCre$tionTime.BetTimeF

    . session.BetL$st2ccesse! session.BetCre$tionTimeF

    E. session.BetM$x@n$ctive@nterv$l 6 session.BetCre$tionTimeF

    . session.BetL$st2ccesse!Time 6 session.BetCre$tionTimeF

    2ns=er:

    Ex(l$n$tion:

    Questions H1. iven the de,nition of =yoJect and that an instance of =yoJect

    is ound as a session attriute)

    G. package com.example

    H. pulic class =yoJect implements

    1. Javax.servlet.http."ttp0ession%inding8istener C

    11. ;; class ody code here

    1*. P

    3hich is true#

    A. Only a single instance of =yoJect may exist within a session

    %. The unound method of the =yoJect instance is called when the session to

    which it is ound times out

    &. The com.example.=yOJect must e declared as a servlet event listener in

    the we application deployment descriptor

    '. The valuenound method of the =yoJect instance is called when thesession to which it is ound times out

    Answer) '

    Explanation)

    Questions H*. 5our we application re(uires the adding and deleting of many

    session attriutes during a complex use case. A ug report has come in that

    indicates that an important session attriute is eing deleted too soon and a

  • 8/15/2019 Web Component Sample Questions

    35/75

  • 8/15/2019 Web Component Sample Questions

    36/75

    '. authentication

    Answer) '

    Explanation)

    Questions H@. 3hich Java code snippet roles D=A?AE-D and DE=68O5EED in a

    given application#A. pulic class =y0ervlet extends "ttp0ervlet CP

    %. pulic class =y0ervlet extends "ttp0ervlet CP

    &. pulic class =y0ervlet extends "ttp0ervlet CP

    '. pulic class =y0ervlet extends "ttp0ervlet CP

    Answer) A

    Explanation)

    Questions HF. iven the Java code snippet in contextInitiali+ed method of a

    0ervlet&ontext8istner)

    0ervlet-egistration.'ynamic sr 0ervlet-egistration.'ynamic/sc.add0ervlet

    Dmy0ervletD! my0ervlet&lass/

    sr.add=appingD;acD/

    sr.set0ervlet0ecurityElementservlet0ecurityElement/ sr.add=appingD;defD/

    3hich statement is true#

    A. D;acD is mapped to DmyservletD. The servlet0ecurityElementy applies to

    oth D;acD and D;defD.

    %. %oth D;acD and D;defD are mapped to DmyservletD. The

    servlet0ecurityElementy applies to D;acD.

    &. %oth D;acD and D;defD are mapped to DmyservletD. The

    servlet0ecurityElementy applies to D;defD.

    '. %oth D;acD and D;defD are mapped to DmyservletD. Theservlet0ecurityElementy applies to oth D;acD and D;defD.

    E. %oth D;acD and D;defD are mapped to DmyservletD. The

    servlet0ecurityElementy applies to D;acD! ut the ehavior for D;defD is not

    speci,ed.

    Answer) E

    Explanation)

    Questions HG. iven)

    2. class =y0ervlet extends "ttp0ervlet C

    4. pulic void do6ut"ttp0ervlet-e(uest re(!"ttp0ervlet-esponse resp/

    throws 0ervletException! IOException C

  • 8/15/2019 Web Component Sample Questions

    37/75

    only 9http$ method: tags and 9auth$constraint: tags are)

    9http$method:ET9;http$method:

    9http$method:6T9;http$method:

    9auth$constrain:Admin9;auth$constrain:

    3hich four re(uests would e allowed y the container# &hoose four/

    A. A user whose role is Admin can perform a 6T.%. A user whose role is Admin can perform a ET.

    &. A user whose role is Admin can perform a 6O0T.

    '. A user whose role is =emer can perform a 6T.

    E. A user whose role is =emer can perform a 6O0T.

    L. A user whose role is =emer can perform a ET.

    Answer) A!%!&!E

    Explanation)

    Questions HH. iven this fragment in a servlet)

    *2. ifreg.isserIn-oleDAdminD// C

    *4. ;; do stuK

    *

  • 8/15/2019 Web Component Sample Questions

    38/75

    Questions 11. 2 =eb $((lic$tion uses $ cookies to tr$ck $ client $s it n$viB$tes throuBh the ($Bes th$t constitutes the $((lic$tion. 4hich co!e sni((et c$n be use! b" the =eb$((lic$tion to re!uce the ch$nce of $ crosssite scri(tinB $tt$ck b" settinB some (ro(ert" ofthe cookie before returninB it to the client62. cookie.setHtt(3nl"true8. cookie.setM$x2Be#-C. cookie.set,$th&/&.

    cookie.setAecuretrue2ns=er: 2

    Ex(l$n$tion:

    Questions 1. Given the (ortion of $ v$li! ?$v$ EE =eb $((lic$tionDs !irector" structure:ou =$nt to kno= =hether ile1.html5 ile.html5 $n!/or ile#.html is (rotecte! from!irect $ccess b" "our =eb clientDs bro=sers. 4h$t st$tement is true6

    2. 2ll three files $re !irectl" $ccessible.8. 3nl" ile1.html is !irectl" $ccessible.C. 3nl"

    ile.html is !irectl" $ccessible.. 3nl" ile#.html is !irectl" $ccessible.E. 3nl" ile1.html

    $n! ile.html $re !irectl" $ccessible.. 3nl" ile1.html $n! ile#.html $re !irectl"

    $ccessible.G. 3nl" ile.html $n! ile#.html $re !irectl" $ccessible.

    2ns=er: 8

    Ex(l$n$tion:

    Questions 1#. Given $ =eb fr$Bment '$r file5 =here shoul! =e (ut the =eb fr$Bment.xml

    insi!e the '$r file6

    2. 4E8@*8. MET2@*C. 4E8@*/lib. 4E8@*/cl$ssesE. MET2@*/services

    2ns=er: C

  • 8/15/2019 Web Component Sample Questions

    39/75

    Ex(l$n$tion:

    Questions 1). Given the fr$Bment from ?$v$ EE !e(lo"ment !escri(tor:

    #)1.

    #). #)#.

    /m$inError.'s(

    #)).

    #)+.

    #)-. #).

    /c$stError.'s(

    #)0.

    @f the =eb $((lic$tion $ssoci$te! =ith the fr$Bment $bove thro=s $ Cl$ssC$stExce(tion.

    4hich st$tement is true62. The !e(lo"ment !escri(tor is inv$li!.8. The cont$iner invokes m$inError.'s(C. The

    cont$iner invokes c$stError.'s(. *either m$inError.'s( nor c$stError.'s( is invoke!.

    2ns=er: C

    Ex(l$n$tion:

    Questions 1+. ou h$ve built $ =eb $((lic$tion th$t "ou license to sm$ll businesses. The

    =eb$(( uses $ context ($r$meter5 c$lle! licenseExtension5 =hich en$bles cert$in $!v$nce!fe$tures b$se! on "our clientDs license ($ck$Be. 4hen $ client ($"s for $ s(ecific service5

    "ou (rovi!e them =ith $ license extension ke" th$t the" insert into the of

    the !e(lo"ment !escri(tor. *ot ever" client =ill h$ve this context ($r$meter so "ou nee! to

    cre$te $ context listener to set u( $ !ef$ult v$lue in the licenseExtension ($r$meter.

    4hich co!e sni((et =ill $ccom(lish this Bo$l6

    2. ou c$nnot !o this bec$use context ($r$meters C2**3T be $ltere!

     (roBr$mm$tic$ll".8. ;

    C. ;

    . context.reset@nit,$r$meterlicenseExtensionD E2PLTF ;

    E. context.set@nit,$r$meterlicenseExtensionD E2PLTF ;

    2ns=er: 2

    Ex(l$n$tion:

  • 8/15/2019 Web Component Sample Questions

    40/75

    Questions 1-. 4hich of the follo=inB $re $ttributes of the $nnot$tion

     '$v$x.servlet.$nnot$tion.4ebiler6

    i *$me

    ii servlet*$mes

    iii url,$tterns

    iv !is($tcherT"(es

    v su((ort2s"nc

    2. iii onl"8. iii $n! ivC. ii5 iii $n! iv. iii5 iv $n! vE. ii5 iii5 iv $n! v

    2ns=er: 8

    Ex(l$n$tion:

    Questions 1. 4hich of follo=inB $nnot$tions c$n be use! in $ servlet cl$ss6

    i X'$v$x.$nnot$tion.Iesource

    ii X'$v$x.$nnot$tion.,reestro"

    iii X'$v$x.$nnot$tion.securit".Iun2s

    iv X'$v$x.$nnot$tion.securit".Ioles2llo=e!

    v X'$v$x.servlet.$nnot$tion.4ebAervlet

    2. v onl"8. i $n! vC. i5 ii5 iii $n! v. i5 ii5 iv $n! vE. i5 ii5 iii5 iv

    $n! v

    2ns=er: 8

    Ex(l$n$tion:

    Questions 10. 4hen usinB the X4ebListener $nnot$tion5 the cl$ss on =hich the

    $nnot$tion is $((lie! to must $lso im(lement $t le$st one o the follo=inB interf$ces 6

    Choose t=o:

    2. IeuestListener8. 2ttributeListenerC. AervletContextListener. Htt(AessionListenerE.

    Aession2ttributeListener. 2s"ncListener 

    2ns=er: C5

    Ex(l$n$tion:

  • 8/15/2019 Web Component Sample Questions

    41/75

    1.You are creating a JSP page to display a collection of data. This data can be displayed in several different

    ways so the architect on your project decided to create a generic servlet that generates a commadelimited

    string so that various pages can render the data in different ways. This servlet takes on reuest parameter!

    object"#.

    $ssume that this servlet is mapped to the %&' pattern! ()*+",-(data.

    "n the JSP you are creating you need to split this string into its elements separated by commas and

    generate an /T0' ul2 list from the data.)hich JST' code snippet will accomplish this goal3

    $.c!import var&eader45dataString5 url45()*+",-(data52

    c!param name45object"#5 value4567current8"#95 (2

    (c!import2

    ul2

    c!forTokens items567dataString.split:;;

  • 8/15/2019 Web Component Sample Questions

    42/75

    You have decided to use the Simple tag model to create this tag handler.

    )hich tag handler method will accomplish this goal3

    $.public void doTag:< throw Jsp*Bception 7

    try 7

    for : *num value ! get*numAalues:< < 7 page=onteBt.set$ttribute:;enumAalue; value

  • 8/15/2019 Web Component Sample Questions

    43/75

    using the J>S* semantics of get&esource.

    *.&esources in the )$& class directory or in any of the J$& files within the library directory =$,,8T be

    accessed using the J>S* semantics of get&esource. $nswer! = #

    H.)hich three are true about the /ttpServlet&euest)rapper class3 :=hoose three.<

    $.The /ttpServlet&euest)rapper is an eBample of the #ecorator pattern.

    +.The /ttpServlet&euest)rapper can be used to eBtend the functionality of a servlet reuest.

    =.$ subclass of /ttpServlet&euest)rapper =$,,8T modify the behavior of the get&eader method.

    #.$n /ttpServlet&euest)rapper may be used only by a class implementing the javaB.servlet.-ilter

    interface.

    *.$n /ttpServlet&euest)rapper =$,,8T be used on the reuest passed to the &euest#ispatcher.include

    method.

    -.$n /ttpServlet&euest)rapper may modify the header of a reuest within an object implementing the

     javaB.servlet.-ilter interface.

    $nswer! $ + -

    I.iven an /ttpServlet&euest reuest and an /ttpServlet&esponse response!

    E1! /ttpSession session 4 null@

    E>! (( insert code here

    ED! if:session 44 null< 7

    EE! (( do something if session does not eBist

    EG! 9 else 7

    EH! (( do something if session eBists

    EI! 9

    To implement the design intent which statement must be inserted at line E>3 $.session 4 response.getSession:

  • 8/15/2019 Web Component Sample Questions

    44/75

    -.$ user whose role is 0ember can perform a *T. $nswer! $ + = *

    L.-or debugging purposes you need to record how many times a given JSP is invoked before the user5s

    session has been created.

    The JSP5s destroy method stores this information to a database.

    )hich JSP code snippet keeps track of this count for the lifetime of the JSP page3

    $.MN int count 4 C@ M2

    M if : reuest.getSession:false< 44 null < countOO@ M2 +.M int count 4 C@ M2

    M if : reuest.getSession:false< 44 null < countOO@ M2 =.M int count 4 C@

    if : reuest.getSession:false< 44 null < countOO@ M2 #.M int count 4 C@

    if : reuest.getSession:false< 44 null < countOO@ M2 *.MN int count 4 C@

    if : reuest.getSession:false< 44 null < countOO@ M2 $nswer!$

    1C.You have built a collection of custom tags for your web application. The T'# file is located in the file!

     ()*+",-(myTags.Bml. You refer to these tags in your JSPs using the symbolic name! myTags.

    )hich deployment descriptor element must you use to make this link between the symbolic name and the

    T'# file name3 $.taglib2

    name2myTags(name2

    location2()*+",-(myTags.Bml(location2

    (taglib2

    +.tags2

    name2myTags(name2

    location2()*+",-(myTags.Bml(location2

    (tags2

    =.tags2

    tagsuri2myTags(tagliburi2

    tagslocation2()*+",-(myTags.Bml(tagslocation2

    (tags2

    #.taglib2

    tagliburi2myTags(tagliburi2

    tagliblocation2()*+",-(myTags.Bml(tagliblocation2

    (taglib2 $nswer!#

    11.1! package com!eBample@

    >! import java!util!F@D! public class $ppliance 7

    E! private 0ap props@

    G! public $ppliance:< 7

    H! this!props 4 new /ash0ap getProperties:< 7

    1C! return this!props@

    11! 9

    1>! private void initiali?e:< 7

    1D! (( code to load appliance properties

  • 8/15/2019 Web Component Sample Questions

    45/75

    1E! 9

    1G! 9

    =lick the *Bhibit button .

    The $ppliance class is a Singleton that loads a set of properties into a 0ap from an eBternal data source.

    $ssume!

    3 $n instance of the $ppliance class eBists in the applicationscoped attribute appl3 The appliance object includes QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ

    the name property that QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ maps to the value =obia

    3 The reuestscoped attribute prop has the value name.

    )hich two *' code snippets will display the string =obia3 :=hoose two.>! 9

    >D!

    >E! public double getPrice:< 7

    >G! return price@>H! 9

    >I!

    >K! public void setPrice:double price< 7

    >L! this!price 4 price@

    DC! 9

    D1! 9

    =lick the *Bhibit button. iven!

    1C! form action45createQproduct.jsp52

  • 8/15/2019 Web Component Sample Questions

    46/75

    11! Product ,ame! input type45teBt5 name45prod,ame5(2br(2

    1>! Product Price! input type45teBt5 name45prodPrice5(2br(2

    1D! (form2

    -or a given product instance which three jsp!setProperty attributes must be used to initiali?e its properties

    from the /T0' form3 :=hoose three.<

    $.id

    +.name=.type

    #.param

    *.property

    -.reParam .attribute $nswer!+ # *

    1D.$ssume that a news tag library contains the tags lookup and item!

    lookup &etrieves the latest news headlines and eBecutes the tag body once for each headline. *Bposes a

    ,*ST*# pagescoped attribute called headline of type com.eBample./eadline containing details for that

    headline.

    item 8utputs the /T0' for a single news headline. $ccepts an attribute info of type com.eBample./eadlinecontaining

    details for the headline to be rendered.)hich snippet of JSP code returns the latest news headlines in an

    /T0' table one per row3

    $.table2

    tr2

    td2

    news!lookup (2

    news!item info4;67headline9; (2

    (td2

    (tr2

    (table2

    +.news!lookup (2

    table2tr2

    td2news!item info4;67headline9; (2(td2

    (tr2

    (table2

    =.table2

    news!lookup2

    tr2

    td2news!item info4;67headline9; (2(td2

    (tr2

    (news!lookup2

    (table2

    #.table2

    tr2

    news!lookup2

    td2news!item info4;67headline9; (2(td2

    (news!lookup2

    (tr2

    (table2 $nswer!=

  • 8/15/2019 Web Component Sample Questions

    47/75

    1E.You are creating a web form with this /T0'!

    11! form action4;send8rder.jsp;2

    1>! input type4;teBt; name4;credit=ard;2

    1D! input type4;teBt; name4;eBpiration#ate;2

    1E! input type4;submit;2

    1G! (form2

    )hich /TTP method is used when sending this reuest from the browser3 $.*T

    +.P%T

    =.P8ST

    #.S*,# *.-8&0 $nswer! $

    1G.Your web application reuires the ability to load and remove web files dynamically to the web container5s

    file system.

    )hich two /TTP methods are used to perform these actions3 :=hoose two.

  • 8/15/2019 Web Component Sample Questions

    48/75

    1K.)hich retrieves all cookies sent in a given /ttpServlet&euest reuest3 $.reuest.get=ookies:<

    +.reuest.get$ttributes:<

    =.reuest.getSession:

  • 8/15/2019 Web Component Sample Questions

    49/75

  • 8/15/2019 Web Component Sample Questions

    50/75

    $. 1C! =ookie c 4 reuest.get=ookie:;username;

  • 8/15/2019 Web Component Sample Questions

    51/75

  • 8/15/2019 Web Component Sample Questions

    52/75

    #. response.set"nt/eader:;'ength; number8f+ytes

  • 8/15/2019 Web Component Sample Questions

    53/75

    DD.)hich statement is true if the doStartTag method returns *A$'Q+8#YQ+%--*&*# 3 $. The tag handler must implement +odyTag.

    +. The do$fter+ody method is ,8T called.

    =. The set+ody=ontent method is called once.

    #. "t is never legal to return *A$'Q+8#YQ+%--*&*# from doStartTag. $nswer! =

    DE.G! public class 0yTag/andler eBtends TagSupport 7

    H! public int doStartTag:< throws Jsp*Bception 7

    I! try 7

    K! )riter out 4 page=onteBt.get&esponse:

  • 8/15/2019 Web Component Sample Questions

    54/75

  • 8/15/2019 Web Component Sample Questions

    55/75

    ability to repopulate the form field with the reuest parameters from the user5s last reuest. -or eBample if

    the user entered ;Samantha; in the teBt field called first,ame then the form is repopulated like this!

    input type45teBt5 name45first,ame5 value45Samantha5 (2

    )hich tag handler method will accomplish this goal3

    $. public int doStartTag:< throws Jsp*Bception 7 Jsp=onteBt ctB 4 getJsp=onteBt:

  • 8/15/2019 Web Component Sample Questions

    56/75

    1>! tl!task name4;0ow the lawn; (2

    1D! tl!task name4;-eed the dog; (2

    1E! tl!task name4;#o the laundry; (2

    1G! (tl!task'ist2

    The tl!task tag supplies information about a single task while the tl!task'ist tag does the final output. The

    tag handler for tl!task'ist is Task'istTag. The tag handler for tl!task is TaskTag. +oth tag handlers eBtend

    +odyTagSupport.)hich allows the tl!task'ist tag to get the task names from its nested tl!task children3

    $. "t is impossible for a tag handler that eBtends +odyTagSupport to communicate with its parent and child

    tags.

    +. "n the Task'istTag.doStartTag method call super.get=hildTags:< and iterate through the results. =ast each

    result to a TaskTag and call get,ame:

  • 8/15/2019 Web Component Sample Questions

    57/75

    the tag handler for n!recurse to output the nesting depth of the deepest n!recurse tag3

    $. "t is impossible to determine the deepest nesting depth because it is impossible for tag handlers that

    eBtend SimpleTagSupport to communicate with their parent and child tags.

    +. =reate a private nonstatic attribute in the tag handler class called count of type int initiali?ed to C.

    "ncrement count in the doTag method. "f the tag has a body invoke the fragment for that body. 8therwise

    output the value of count.

    =. Start a counter at 1. =all get=hildTags:

  • 8/15/2019 Web Component Sample Questions

    58/75

    EG.

    1!

    >!

    D!

    I! 1.C

    K! h

    L! http!((eBample.com(tld(highlight1C!

    11! highlight

    1>! com.eBample./ighlightTag

    1D! scriptless

    1E!

    1G! color

    1H! true

    1I!

    1K! true

    1L!

    >C!

    =lick the *Bhibit button.

    The h!highlight tag renders its body highlighting an arbitrary number of words each of which is passed asan attribute :word1 word> ...4;low;2

    1>! high medium low

    1D! (h!highlight2

    iven that /ighlightTag eBtends SimpleTagSupport which three steps are necessary to implement the tag

    handler for the highlight tag3 :=hoose three

  • 8/15/2019 Web Component Sample Questions

    59/75

    public void put$ttribute:String name 8bject value< 7

    this.attributes.put:name value.tag both reside in ()*+",-(tags(bar the container will consider them part of the

    same tag library.

    $nswer! + *

    EK. )hich two directives are applicable only to tag f iles3 :=hoose two.

  • 8/15/2019 Web Component Sample Questions

    60/75

    *. scriptless

    -. tagdependent

    $nswer!= * -

    Q25.You need to store a Java long primitive attribute, called customerOID, into the

    session scope. Which two code snippets allow ou to insert this value into the session!

    "#hoose two.$

    2. lonB customer3@ % )LFsession.set2ttribute&customer3@&5 ne= LonBcustomer3@F8. lonB customer3@ % )LFsession.setLonB2ttribute&customer3@&5 ne= LonBcustomer3@FC. lonB customer3@ % )LF

    session.set2ttribute&customer3@&5 customer3@F. lonB customer3@ % )LFsession.set*umeric2ttribute&customer3@&5 ne= LonBcustomer3@FE. lonB customer3@ % )LFsession.setLonB2ttribute&customer3@&5 customer3@F. lonB customer3@ % )LFsession.set*umeric2ttribute&customer3@&5 customer3@F

    %nswer& %, #

    Q2'. Your web application uses a simple architecture in which servlets handle

    re(uests and then )orward to a J*+ using a re(uest dispatcher. You need to pass

    in)ormation calculated in the servlet to the J*+ )or view generation. his in)ormation

    must -O be accessible to an other servlet, J*+ or session in the webapp. Which two

    techni(ues can ou use to accomplish this goal!

    "#hoose two.$

    2. 2!! $ttributes to the session ob'ect. 8. 2!! $ttributes on the reuest ob'ect.C. 2!! ($r$meters to the reuest ob'ect.. Pse the ($BeContext ob'ect to $!! reuest $ttributes.

    E. 2!! ($r$meters to the ?A,Ds PIL =hen Bener$tinB the reuest !is($tcher.%nswer& , /

    Q 20. Which three are true about servlet )ilters! "#hoose three.$

    2. 2 filter must im(lement the !estro" metho!.8. 2 filter must im(lement the !oilter metho!.C. 2 servlet m$" h$ve multi(le filters $ssoci$te! =ith it.. 2 servlet th$t is to h$ve $ filter $((lie! to it must im(lement the '$v$x.servlet.

  • 8/15/2019 Web Component Sample Questions

    61/75

    ilterCh$in interf$ce.E. 2 filter th$t is ($rt of $ filter ch$in ($sses control to the next filter in the ch$in b"invokinB the ilterCh$in.for=$r! metho!.. or e$ch element in the =eb $((lic$tion !e(lo"ment !escri(tor5 multi(leinst$nces of $ filter m$" be cre$te! b" the =eb cont$iner.

    %nswer& %, , #

    Q1.*ervlet % receives a re(uest that it )orwards to servlet within another web

    application in the same web container. *ervlet % needs to share data with servlet

    and that data must not be visible to other servlets in %s web application. In which

    ob3ect can the data that % shares with

    be stored!

    2. Htt(Aession 8. AervletConfiB

    C. AervletContext . Htt(AervletIeuest

    E. Htt(AervletIes(onse

    %nswer& D

    Q2.our web site has man user4customiable )eatures, )or e6ample )ont and color

    pre)erences on web pages. Your I department has alread built a subsstem )or user

    pre)erencessing the Java */ plat)orms lang.util.pre)s pac7age %+Is, and ou have

    been ordered to reuse this subsstem in our web application. You need to create an

    event listener that constructs the pre)erences actor and stores it in the application

    scope )or later use. 8urthermore, this )actor re(uires that the 9:; to a database

    must be declared in the deploment descriptor li7e this&

  • 8/15/2019 Web Component Sample Questions

    62/75

    ;

    // more co!e here

    ;

    8. (ublic cl$ss ,refs$ctor"@niti$liNer im(lements AervletContextListener

     (ublic voi! contextCre$te!AervletContext ctx

    AtrinB (refsPIL % ctx.Bet@nit,$r$meter&(refsbPIL&F

    ,references$ctor" m"$ctor" % m$ke$ctor"(refsPILF

    ctx.set2ttribute&m",refs$ctor"&5 m"$ctor"F

    ;

    // more co!e here

    ;

    C. (ublic cl$ss ,refs$ctor"@niti$liNer im(lements AervletContextListener

     (ublic voi! context@niti$liNe!AervletContextEvent e

    AervletContext ctx % e.BetAervletContextF

    AtrinB (refsPIL % ctx.Bet@nit,$r$meter&(refsbPIL&F,references$ctor" m"$ctor" % m$ke$ctor"(refsPILF

    ctx.set2ttribute&m",refs$ctor"&5 m"$ctor"F

    ;

    // more co!e here

    ;

    . (ublic cl$ss ,refs$ctor"@niti$liNer im(lements ContextListener

     (ublic voi! contextCre$te!AervletContext ctx

    AtrinB (refsPIL % ctx.Bet,$r$meter&(refsbPIL&F

    ,references$ctor" m"$ctor" % m$ke$ctor"(refsPILF

    ctx.(ut2ttribute&m",refs$ctor"&5 m"$ctor"F;

    // more co!e here

    ;

    %nswer& #

    Q?.developer wants a web application to be noti)ied when the application is about to

    be shut down. Which two actions are necessar to accomplish this goal! "#hoose two.$

    2. inclu!e $ listener !irective in $ ?A, ($Be

    8. confiBure $ listener in the TL file usinB the elementC. inclu!e $

  • 8/15/2019 Web Component Sample Questions

    63/75

    !e(lo"ment

    G. inclu!e $ cl$ss im(lementinB Htt(Aession2ttributeListener $s ($rt of the =eb

    $((lic$tion !e(lo"ment

    %nswer& D, /

    Q

  • 8/15/2019 Web Component Sample Questions

    64/75

  • 8/15/2019 Web Component Sample Questions

    65/75

    2. 2n exce(tion is thro=n $t runtime b" AourceAervlet.8. 2n exce(tion is thro=n $t runtime b" estin$tionAervlet.C. 3nl" &hello from !est& $((e$rs in the res(onse out(ut stre$m.. 8oth &hello from source& $n! &hello from !est& $((e$r in the res(onse out(ut stre$m.%nswer& %

    QB.Civen the de)inition o) *ervlet&

    11. public class *ervlet e6tends Attp*ervlet E12. public void service"Attp*ervlet:e(uest re(uest,

    1?. Attp*ervlet:esponse response$

    1

  • 8/15/2019 Web Component Sample Questions

    66/75

    1K. session.get%ttribute"Hm%ttributeH$$G

    2L. M

    21. M

    What is the result when a re(uest is sent to *ervlet!

    2. 2n @lleB$lAt$teExce(tion is thro=n $t runtime.8. 2n @nv$li!AessionExce(tion is thro=n $t runtime.C. The strinB &v$lue%null& $((e$rs in the res(onse stre$m.. The strinB &v$lue%m"2ttributeO$lue& $((e$rs in the res(onse stre$m.

    %nswer& %

    QK.You need to store a Java long primitive attribute, called customerOID, into the

    session scope. Which two code snippets allow ou to insert this value into the session!

    "#hoose two.$

    2. lonB customer3@ % )LFsession.set2ttribute&customer3@&5 ne= LonBcustomer3@F8. lonB customer3@ % )LFsession.setLonB2ttribute&customer3@&5 ne= LonBcustomer3@FC. lonB customer3@ % )LFsession.set2ttribute&customer3@&5 customer3@F. lonB customer3@ % )LFsession.set*umeric2ttribute&customer3@&5 ne= LonBcustomer3@FE. lonB customer3@ % )LFsession.setLonB2ttribute&customer3@&5 customer3@F. lonB customer3@ % )LFsession.set*umeric2ttribute&customer3@&5 customer3@F

    %nswer& %, #

    Q1L.Your web application re(uires the adding and deleting o) man session attributes

    during a comple6 use case. % bug report has come in that indicates that an important

    session attribute is being deleted too soon and a -ull+ointer/6ception is being thrown

    several interactions a)ter the )act. You have decided to create a session event listener

    that will log when attributes are being deleted so ou can trac7 down when the

    attribute is erroneousl being deleted.

    Which listener class will accomplish this debugging goal!

    2. Cre$te $n Htt(Aession2ttributeListener cl$ss $n! im(lement the $ttributeelete! metho!$n! loB the $ttribute n$me usinB the Bet*$me metho! on the event ob'ect.

  • 8/15/2019 Web Component Sample Questions

    67/75

    8. Cre$te $n Htt(Aession2ttributeListener cl$ss $n! im(lement the $ttributeIemove!metho! $n! loB the $ttribute n$me usinB the Bet*$me metho! on the event ob'ect.

    C. Cre$te $n Aession2ttributeListener cl$ss $n! im(lement the $ttributeIemove! metho!$n! loB the $ttribute n$me usinB the Bet2ttribute*$me metho! on the event ob'ect.

    . Cre$te $n Aession2ttributeListener cl$ss $n! im(lement the $ttributeelete! metho! $n!loB the $ttribute n$me usinB the Bet2ttribute*$me metho! on the event ob'ect.%nswer&

    Q11.One o) the use cases in our web application uses man session4scoped attributes.

    %t the end o) the use case, ou want to clear out this set o) attributes )rom the session

    ob3ect.

    %ssume that this static variable holds this set o) attribute names&

    2L1. private static )inal *et=*tring> 9*/N#%*/N%:*G

    2L2. static E2L?. 9*/N#%*/N%:*.add"HcustomerOIDH$G

    2L

  • 8/15/2019 Web Component Sample Questions

    68/75

    2. reuest.set2ttribute&or!er@&5 [email protected]&'s(PIL&5 's(PILFIeuestis($tcher vie=% context.BetIeuestis($tcher&/4E8@*/retreive3r!er.!o&Fvie=.for=$r!reuest5 res(onseF

    8. reuest.set,$r$meter&or!er@&5 [email protected],$r$meter&'s(PIL&5 's(PILFis($tcher vie=% reuest.Betis($tcher&/4E8@*/retreive3r!er.!o&Fvie=.for=$r!Ieuestreuest5 res(onseF

    C. AtrinB T%&/4E8@*/retreive3r!er.!o6or!er@%S!Y's(PIL%Ss&FAtrinB url % AtrinB.form$tT5 or!er@5 's(PILFIeuestis($tcher vie=% context.BetIeuestis($tcherurlF

    vie=.for=$r!reuest5 res(onseF

    . AtrinB T%&/4E8@*/retreive3r!er.!o6or!er@%S!Y's(PIL%Ss&FAtrinB url % AtrinB.form$tT5 or!er@5 's(PILFis($tcher vie= % context.Betis($tcherurlFvie=.for=$r!Ieuestreuest5 res(onseF

    %nswer& #

    Q1?.You want to create a )ilter )or our web application and our )ilter willimplement 3ava6.servlet.8ilter.

    Which two statements are true! "#hoose two.$

    2. our filter cl$ss must im(lement $n init metho! $n! $ !estro" metho!.

    8. our filter cl$ss must $lso im(lement '$v$x.servlet.ilterCh$in.

    C. 4hen "our filter ch$ins to the next filter5 it shoul! ($ss the s$me $rBuments it receive!

    in its !oilter metho!.

    . The metho! th$t "our filter invokes on the ob'ect it receive! th$t im(lements

     '$v$x.servlet.ilterCh$in c$n invoke either $nother filter or $ servlet.

    E. our filter cl$ss must im(lement $ !oilter metho! th$t t$kes5 $monB other thinBs5 $n

    HTT,AervletIeuest ob'ect $n! $n HTT,AervletIes(onse ob'ect.

    %nswer& %, D

    Q1

    12. =)ilter4name>+aram%dder=@)ilter4name>

  • 8/15/2019 Web Component Sample Questions

    69/75

    1?. =)ilter4class>com.e6ample.+aram%dder=@)ilter4class>

    1

    ...

    2

    25. =)ilter4name>+aram%dder=@)ilter4name>

    2'. =servlet4name>*ervlet=@servlet4name>

    20. =44 insert element here 44>

    2B. =@)ilter4mapping>

    Which element, inserted at line 20, causes the +aram%dder )ilter to be applied when

    *ervlet is invo7ed b another servlet using the :e(uestDispatcher.include method!

    2.

    8. @*CLPE

    C. inclu!e

    . @*CLPE

    E. inclu!e

    %nswer&

    Q15. Your web application uses a simple architecture in which servlets handle

    re(uests and then )orward to a J*+ using a re(uest dispatcher. You need to pass

    in)ormation calculated b the servlet to the J*+G )urthermore, that J*+ uses a custom

    tag and must also process this in)ormation. his in)ormation must -O be accessible

    to an other servlet, J*+ or session in the webapp. Aow can ou accomplish this goal!

    2. Atore the !$t$ in $ (ublic inst$nce v$ri$ble in the servlet.8. 2!! $n $ttribute to the reuest ob'ect before usinB the reuest !is($tcher.

    C. 2!! $n $ttribute to the context ob'ect before usinB the reuest !is($tcher.

    . This C2**3T be !one $s the t$B h$n!ler h$s no me$ns to extr$ct this !$t$.

    %nswer&

    Q1'. % developer chooses to avoid using *inglehreadodel but wants to ensure that

    data is updated in a thread4sa)e manner. Which two can support this design goal!

    "#hoose two.$

    2. Atore the !$t$ in $ loc$l v$ri$ble.

    8. Atore the !$t$ in $n inst$nce v$ri$ble.C. Atore the !$t$ in the Htt(Aession ob'ect.

    . Atore the !$t$ in the AervletContext ob'ect.

    E. Atore the !$t$ in the AervletIeuest ob'ect.

    %nswer& %, /

  • 8/15/2019 Web Component Sample Questions

    70/75

    Q10. Your web application uses a simple architecture in which servlets handle

    re(uests and then )orward to a J*+ using a re(uest dispatcher. You need to pass

    in)ormation calculated in the servlet to the J*+ )or view generation. his in)ormation

    must -O be accessible to an other servlet, J*+ or session in the webapp. Which two

    techni(ues can ou use to accomplish this goal!"#hoose two.$

    2. 2!! $ttributes to the session ob'ect.

    8. 2!! $ttributes on the reuest ob'ect.

    C. 2!! ($r$meters to the reuest ob'ect.

    . Pse the ($BeContext ob'ect to $!! reuest $ttributes.

    E. 2!! ($r$meters to the ?A,Ds PIL =hen Bener$tinB the reuest !is($tcher.

    %nswer&

    Q1B. Civen&

    *tring value F get*ervlet#onte6t"$.getInit+arameter"H)ooH$G

    in an Attp*ervlet and a web application deploment descriptor that contains&

    =conte6t4param>

    =param4name>)oo=@param4name>

    =param4value>)rodo=@param4value>

    =@conte6t4param>

    Which two are true! "#hoose two.$

    2. The foo initi$liN$tion ($r$meter C2**3T be set (roBr$mm$tic$ll".

    8. Com(il$tion f$ils bec$use Bet@nit,$r$meter returns t"(e 3b'ect.

    C. The foo initi$liN$tion ($r$meter is *3T $ servlet initi$liN$tion ($r$meter.

    . Com(il$tion f$ils bec$use AervletContext !oes *3T h$ve $ Bet@nit,$r$meter metho!.

    E. The foo ($r$meter must be !efine! =ithin the element of the !e(lo"ment

    !escri(tor.

    . The foo initi$liN$tion ($r$meter c$n $lso be retrieve! usinB

    BetAervletConfiB.Bet@nit,$r$meter&foo&.

    %nswer& %, #

    Q1K. #lic7 the /6hibit button. Civen the web application deploment descriptor

    elements&

    11. =)ilter>

    12. =)ilter4name>+aram%dder=@)ilter4name>

    1?. =)ilter4class>com.e6ample.+aram%dder=@)ilter4class>

    1

  • 8/15/2019 Web Component Sample Questions

    71/75

    ?1. =)ilter4mapping>

    ?2. =)ilter4name>+aram%dder=@)ilter4name>

    ??. =servlet4name>Destination=@servlet4name>

    ?

    ...

    55. =servlet4mapping>

    5'. =servlet4name>Destination=@servlet4name>

    50. =url4pattern>@dest@Destination=@url4pattern>

    5B. =@servlet4mapping>

    What is the result o) a client re(uest o) the *ource servlet with no (uer string!

    2. The out(ut &filter2!!e! % null& is =ritten to the res(onse stre$m.

    8. The out(ut &filter2!!e! % $!!e!8"ilter& is =ritten to the res(onse stre$m.

    C. 2n exce(tion is thro=n $t runtime =ithin the service metho! of the Aource servlet.

    . 2n exce(tion is thro=n $t runtime =ithin the service metho! of the estin$tion servlet.

  • 8/15/2019 Web Component Sample Questions

    72/75

    %nswer& %

    Q2L.Civen a 8ilter class de)inition with this method&

    21. public void do8ilter"*ervlet:e(uest re(uest,

    22. *ervlet:esponse response,2?. 8ilter#hain chain$

    2

  • 8/15/2019 Web Component Sample Questions

    73/75

    Which code snippet deletes these attributes )rom the session ob3ect!

    2. session.remove2llPAEUC2AEU2TTIAF

    8. for AtrinB $ttr : PAEUC2AEU2TTIA

    session.remove$ttrF

    ;

    C. for AtrinB $ttr : PAEUC2AEU2TTIA

    session.remove2ttribute$ttrF

    ;

    . for AtrinB $ttr : PAEUC2AEU2TTIA

    session.!elete2ttribute$ttrF ;

    E. session.!elete2ll2ttributesPAEUC2AEU2TTIAF

    %nswer& #

    Q2?. You need to store a )loating point number, called s(uare, in the session scope.

    Which two code snippets allow ou to retrieve this value! "#hoose two.$

    2. flo$t Tsu$re % session.Betlo$t2ttribute&Tsu$re&F

    8. flo$t Tsu$re % lo$t session.Bet2ttribute&Tsu$re&F

    C. flo$t Tsu$re % flo$t session.Bet*umeric2ttribute&Tsu$re&F

    . flo$t Tsu$re % lo$t session.Bet2ttribute.&Tsu$re&.flo$tO$lueF

    E. flo$t Tsu$re % lo$t session.Betlo$t2ttribute.&Tsu$re&.flo$tO$lueF

    . flo$t Tsu$re % lo$t session.Bet*umeric2ttribute.&Tsu$re&.flo$tO$lueF

    %nswer& , D

    Q2

  • 8/15/2019 Web Component Sample Questions

    74/75

    con)igure a servlet conte6t event listener named com.e6ample.;istener.

    %nswers&

    =listener>

      =listener4class>com.e6ample.;istener= listener4class>

    =@listener>

     

    Q 2K. Which is true about the web container re(uest processing model!

    2. The init metho! on $ filter is c$lle! the first time $ servlet m$((e! to th$t filter is

    invoke!.

    8. 2 filter !efine! for $ servlet must $l=$"s for=$r! control to the next resource in the

    filter ch$in.

    C. ilters $ssoci$te! =ith $ n$me! servlet $re $((lie! in the or!er the" $((e$r in the =eb

    $((lic$tion !e(lo"ment !escri(tor file.

    . @f the init metho! on $ filter thro=s $n Pn$v$il$bleExce(tion5 then the cont$iner =ill

    m$ke no further $ttem(t to execute it.

    %nswer& #

  • 8/15/2019 Web Component Sample Questions

    75/75

    Q?L. Your I department is building a lightweight 8ront #ontroller servlet that

    invo7es an application logic ob3ect with the inter)ace&

    public inter)ace %pplication#ontroller E

    public *tring invo7e"Attp*ervlet:e(uest re(uest$

    M

    he return value o) this method indicates a smbolic name o) the ne6t view. 8rom this

    name, the 8ront #ontroller servlet loo7s up the J*+ 9:; in a con)iguration table. his

    9:; might be an absolute path or a path relative to the current re(uest. -e6t, the

    8ront #ontroller servlet must send the re(uest to this J*+ to generate the view.

    %ssume that the servlet variable re(uest is assigned the current Attp*ervlet:e(uest

    ob3ect and the variable conte6t is assigned the webapps *ervlet#onte6t.

    Which code snippet o) the 8ront #ontroller servlet accomplishes this goal!

    2. is($tcher vie=

    % context.Betis($tchervie=PILF

    vie=.for=$r!Ieuestreuest5 res(onseF

    8. is($tcher vie=

    % reuest.Betis($tchervie=PILF

    vie=.for=$r!Ieuestreuest5 res(onseF

    C. Ieuestis($tcher vie=

    % context.BetIeuestis($tchervie=PILF

    vie=.for=$r!reuest5 res(onseF

    . Ieuestis($tcher vie= % reuest.BetIeuestis($tchervie=PILF

    vie=.for=$r!reuest5 res(onseF

    %nswer& D