• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

HttpSessionBindingListener mock exam question - what's YOUR answer?

 
Ranch Hand
Posts: 1855
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

please view the mock exam question below. What is the correct answer and WHY :roll: ?



Regards,
Darya
 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
F?

becouse each time u set new value for the Att the old one is Unbound?

i jut tryed to test it but im having problems getting it to work at all:
listener Code

calling code inside doGet

web.xml child of <web-app>


and i allways geting the output:

added foo : bar
replaced foo : bar
replaced foo : bar
removed foo : bar


looks like those valueUnbound valueBound r never called?

can u help?
[ September 22, 2005: Message edited by: Ner min ]
 
Darya Akbari
Ranch Hand
Posts: 1855
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ner,

sorry I can't look at your code right now but maybe tomorrow, since I've my exam tomorrow.

F is not the answer .

Regards,
Darya
 
Ner min
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok, well good luck
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Darya,

I would say the answer would be B.

Statement 1: req.getSession().setAttribute("key", new X());
This should trigger the valueBound on Object X and print B.

Statement 2: req.getSession().setAttribute("key", new X());
a. This should create a new instance of X and trigger the valueBound
and print B.
b. This statement should also trigger the valueUnbound from the
instance created in statement 1 and print UB.

Statement 3: req.getSession().setAttribute("key", "x");
This should trigger the valueUnbound on Object X (that was created
in statement 2) and print "UB.

Statement 4: req.getSession().removeAttribute("key");
prints nothing since "key" has String Object "x".

So to put it all together, I think it should be ....

BBUBUB
 
Darya Akbari
Ranch Hand
Posts: 1855
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Annie,

yes it's B and thanks for your wonderful explanation .

Regards,
Darya
 
Ranch Hand
Posts: 372
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But I thought in step 2 that Annie had described, the old attribute needs to be unbound FIRST and THEN the new attribute would be bound. So should the order not be UB and then B?
 
Darya Akbari
Ranch Hand
Posts: 1855
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Sathish,

I thought the same as you first. But then no answer would fit. Hence I came to the conclusion that first bound and then unboud happens.

Regards,
Darya
 
Ner min
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Darya ,

but way new X() trigers bound and "x" not?
Does that mean that String Objects cant have(be bound) to listeners?
That would explain way my code dont funct?
 
Darya Akbari
Ranch Hand
Posts: 1855
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
of course not . You declare valueBound and valueUnbound only for your X class.

Regards,
Darya
 
Ranch Hand
Posts: 228
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Statement 3: req.getSession().setAttribute("key", "x");
This should trigger the valueUnbound on Object X (that was created
in statement 2) and print "UB.




Hello ,
I think the above statement just add an attribute with string as value.It wont trigger the bound or unbound. Only when the attribute class is added or removed we have the bound and unbound triggering.

LAST UNBOUND IS DUE TO THE removeAttribute method and not due to setAttribute("key","x")
 
reply
    Bookmark Topic Watch Topic
  • New Topic