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

HFSJ question on session attribute

 
Kelly Wood
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This question comes from the end of chapters 6 session management of head first servlet and jsp:

Which statements about session attributes are true?

One of the correct answer is: "Attributes bound into a session are available to any other servlet that belongs to the same ServletContext".

I am not quite sure why this answer is correct. My understanding is that a session attribute is only available to a servlet if the session is passed into the servlet in the request parameter. That is, a servlet can not just grab a attribute from any session it wants to. Can someone clarify?
 
S.L.Narayanan
Ranch Hand
Posts: 431
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No. Attributes of a session will not be available to any app in the same ServletContext unless that servlet also uses the same Session. You tell the complete questions and answers. One more thing, an attribute with Session scope wont be available to all other apps which are sharing same Request object. For that you need to explicitly put the attribute in the Request attribute or those apps also have to use the same session. Got it?
 
jyothi Reddy
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Kelly,

This is a printing mistake in HFSJ.
The link below answers ur question
http://www.oreilly.com/catalog/headservletsjsp/errata/headservletsjsp.confirmed

Jyothi

----------------------------

SCJP 1.4
 
Bhumika Thakkar
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A request belongs to a Session. If that request is forwarded to another application then even then the session attributes will not be available to it. Is my understanding right?

Session does not migrate from one app to another.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic