• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HttpSessionBindingListener mock exam question - what's YOUR answer?

 
Darya Akbari
Ranch Hand
Posts: 1855
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

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



Regards,
Darya
 
Ner min
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • Quote
  • Report post to moderator
ok, well good luck
 
Annie McCall
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Hi Annie,

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

Regards,
Darya
 
B.Sathish
Ranch Hand
Posts: 372
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • Quote
  • Report post to moderator
of course not . You declare valueBound and valueUnbound only for your X class.

Regards,
Darya
 
Karthik Rajendiran
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
  • 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")
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic