• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Session Management chapter in HF's WCD book

 
Sriram
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
While going thru the mock exam questions at the end of the Session Management chapter, I found this question.

7. which statements about session attributes are true?

A. The return type of HttpSession.getAttribute(String) is Object.
B. The return type of HttpSession.getAttribute(String) is String.
C. Attributes bound into a session are available to any other serlet that
belongs to the same ServletContext
D. Calling setAttribute ("keyA", "valueB") on an HttpSession which already
holds a value for the key keyA will cause an exception to be thrown.
E. Calling setAttribute ("keyA", "valueB") on an HttpSession which already
holds a value for the key keyA will cause the previous value for this
attribute to be replaced with the String valueB

options A, C and E are given as correct options.

Can anybody explain why the option C is correct??
if option C is correct, then what is the diferrence between the session scope and servlet context scope?
 
Sayak Banerjee
Ranch Hand
Posts: 292
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Answer C left off a vital part of the sentence when it was copied from the Servlet specification.
The Servlet specification says:

'Any object bound into a session is available to any other servlet that belongs to
the same ServletContext and handles a request identified as being a part of the same
session.'

Answer C leaves off the final part of the sentence: 'and handles a request identified
as being a part of the same session.' Without this answer C is not correct.


This is mentioned in the Errata List for HFSJ...please check this before posting queries
 
Sriram
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much for the clarification and for the link given for the errors in the book...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic