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 on two questions..(Topic:: Session Migration & EL)

 
Bhavik Patel
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
acme's application was initially developed in non distributed environment.They are now migrating to application server that supports distributed HttpSession Objects.app is marked as distributable in web.xml.which two must be tru
1>J2EE web container must support migration of serialized objects.
2> it must use native serialization for distributable HttpSession objects
3> as per spec,it should store the migrating session objects in the databse
4>storing EJB references in the HttpSession Object might not be supported by J2ee web containers.

my answer is 1,2 but not sure about 4


2>
assume that Bean is valid java bean with property advice;
<% com.example.Bean advisor = new com.example.Bean();
request.setAttribute("foo",advisor);


%>
1>${foo.advise}
2>${request.foo.advice}
3>${requestScope.foo.advice}
4>${requestScope[foo[advice]]}
5>${requestScope["foo"][advice]}

answers are 2,4,5
i have doubt on 4 & 5 as it states [advice] and advice property is not
in the any scope(does it look recursively ?? i guess not )
can someone confirm and explain me the answers pls..
 
Charles Lyons
Author
Ranch Hand
Posts: 836
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<% com.example.Bean advisor = new com.example.Bean();
request.setAttribute("foo",advisor);
%>
1>${foo.advise}
2>${request.foo.advice}
3>${requestScope.foo.advice}
4>${requestScope[foo[advice]]}
5>${requestScope["foo"][advice]}
You didn't actually say what the question was asking; I'm assuming it's "choose the expressions which retrieve the value of the advice property from the foo attribute in the request scope". If not, you'll have to work out the answers from my comments for each possible answer:

(1) This will access the "advise" property on the "foo" scoped attribute. The "foo" object will either be from the page scope if one exists there (and hence is an incorrect answer) or if no page-scoped "foo" attribute exists, it will be the required request-scoped attribute. However, the property accessed is "advise" and not "advice" (is this a typo?).

(2) Incorrect - we don't know of any "request" object.

(3) This accesses the "foo" attribute in the request scope, and then the "advice" property on that object. So this should work okay...

(4) Incorrect - this will only work if we can resolve a "foo" variable first (in one of the scopes, searched in order) and then an "advice" property on that object. It is this property which is then used as the attribute name to retrieve an attribute from the request-scope. This is therefore incorrect.

(5) requestScope["foo"][advice] - this means get the "foo" request-scoped attribute, then retrieve the value the advice [i]variable[i] and then uses the value of that (coerced to a string or int) as the property name/index to access from the "foo" object. Not what we want to do.

I think only 3 is the correct answer (1 is correct if that was a typo and you meant "foo.advice" there).

But I hate questions that are so badly specified for these reasons:
  • If there's a different page-scoped attribute called "foo", then 1 will be incorrect.
  • If there's a scoped attribute called "advice" with the string value "advice" then 5 will in fact be correct.
  • If a "request" scoped attribute in fact is set to reference the ServletRequest (through some non-specified scripting code), then 2 will be correct.


  • Does that answer it?
     
    singh santosh
    Ranch Hand
    Posts: 136
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    hi ,



    well.. your doubt is well profound since "advice" is not any scope .So both 4 and 5 would return empty string (nothing).And yes ,it does not look recursively.

    regards
    -santosh
     
    Bhavik Patel
    Ranch Hand
    Posts: 155
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    hiii guys .. it was typo ..assume that for first option its ${foo.advice} ..it was just typo thanks for very good explanation ..

    for the first question answers are 1,2 ..right ?? 4 is false..
     
    Bhavik Patel
    Ranch Hand
    Posts: 155
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    thanks to charles & singh..Charles it clears my all doubts..thanks
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic