Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt in HFSJ mock exam questions - 9 & 55

 
Mani Jagathesan
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,

Can some one please clear this for me?

Q9. HFSJ says a TLD file may exist in any sub-dir of web-inf.

However, the spec (JSP 7.3.1, pg 1-160) says "When deployed directly into a web appln, the tag library descriptor files must always be in the WEB-INF dir or some sub-dir of it. TLD files should not be placed in /WEB-INF/classes or /WEB-INF/lib."

Doesn't the 2nd part of this make this option invalid in the answers?

I also noticed that HFSJ also had the same answer in the chapter wise mock exam and in the deployment chapter it says the same.

However, the above marked statment from spec leaves me a little confused.




Q55. The valueBound() is fired after each of the setAttribute() and valueUnbound() is fired soon after the removeAttribute().

But, what happens when the third setAttribute("key", "x") is executed? How does this log the output to be UB?

setAttribute("key", new X() ); log output is B
setAttribute("key", new X() ); log output is B
setAttribute("key", "x"); how is it UB here?
removeAttribute("key"); log output is UB

BBUBUB

Thanks for your help.
 
Frederic Esnault
Ranch Hand
Posts: 284
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi !

1. The meaning of "any web-inf subdir" is that you may put in the web-inf dir or any custom subdir you want, like web-inf/blah/foo... lib and classes are indeed special subdirs which are not included by this expression.

You must see the directories as separated entities. For example, web-inf/lib is dissociated from web-inf/class and from web-inf. What they say just mean you are not stuck with the web-inf dir itself, you may create your own subdirs and use them.

2. About the ububububub thing
The X object is an HttpSessionBindingListener obviously.
So :
setAttribute("key", new X() );
X is bound to session, log : B

setAttribute("key", new X() );
a new X object is bound to session, log : BB
The previous X object is removed from session (replaced by the new X), so its valueUnbound is called, log : BBUB

setAttribute("key", "x");
the attribute named key value is set to the "x" String. So the X object attribute is removed to be replaced by the String "x". The valueUnbound method is called, log: BBUBUB

removeAttribute("key");
The key attribute does not refer to a X object, so no listener method is called, no log.

Result : BBUBUB
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic