• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Session related

 
Amruth Puppala
Ranch Hand
Posts: 295
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Question is from HFSJ 1st edition.
Please select correct answer.


Which statements about session attibutes are true?
A. The return types of HttpSession.getAttribute(String)is Object
B. The return types of HttpSession.getAttribute(String)is String
C. Attribute bound into a session are available to any other servlet that belongs to the same ServletContext.
D. Calling setAttribute("keyA","ValueB") on an HttpSessopn which already hold a value for the key keyA will cause an exception
E. Calling setAttribute("keyA","ValueB") on an HttpSessopn which already hold a value for the key keyA will cause the previous value for this attribute to be replaces with the String valueB.
 
Anand Bhatt
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The correct options are:
A. The return types of HttpSession.getAttribute(String)is Object
C. Attribute bound into a session are available to any other servlet that belongs to the same ServletContext.
E. Calling setAttribute("keyA","ValueB") on an HttpSessopn which already hold a value for the key keyA will cause the previous value for this attribute to be replaces with the String valueB.

Right?
 
Amruth Puppala
Ranch Hand
Posts: 295
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah your answer is correct,
But how come C is correct.
How come any other servlet that belongs to the same ServletContext have access to sesion attribute. If the Servlet/JSP is not participating in the session then is it not possible access that Session attribute.

In my view: If the statement is like
"Attribute bound into a session are available to any other servlet that belongs to the same ServletContext and (are participating the same session/ <%@ page session="false" %> kind ")
 
Musab Al-Rawi
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A is correct
C is not correct, it would have been correct if it said "to the same session" not ServletContext
E is correct as the object will be replaced

check this post
[ July 29, 2008: Message edited by: Musab Al-Rawi ]
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi chintu,


1.session is an implicit object in jsp. more over session is a collection of httprequest over a period of time(representation of a user).. so until session is timeout...it is available in the particular webapplication... so you can access the session in all the
servlet until session is invalidate..


2.<%@ session="false"%>

if you declare explicit in jsp...implicit session object is not available for the particular jsp only(but you can access the session in servlet)

HOPE THIS WILL HELP YOU
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Musab Al-Rawi:

C is not correct, it would have been correct if it said "to the same session" not ServletContext


Disagree
 
Amruth Puppala
Ranch Hand
Posts: 295
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks you all for your clarification.

Y disagree I didn't understood. please add some more comments
[ July 29, 2008: Message edited by: Chintu sirivennela ]
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi chintu,

about default session object in jsp

hope this may useful to you
 
Amruth Puppala
Ranch Hand
Posts: 295
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi seetharaman,
yeah it is correct about JSP. I got it. JSP always have access to to session.

But Lets say if the servlet is not participating the session will that be able to access those attibutes.
 
Musab Al-Rawi
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
seetharaman,

Option C says:
Attribute bound into a session are available to any other servlet that belongs to the same ServletContext.

this implies that if you have 2 clients A and B (each has his own session) it is possible for user B to access attribute a that belongs to client A's.

Yes in JSP you get a session automatically but that session is not shared with other client.
I think you are mixing two different things here.
Correct me if I am mistaken please.
[ July 29, 2008: Message edited by: Musab Al-Rawi ]
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Musab Al-Rawi:
Option C says:
Attribute bound into a session are available to any other servlet that belongs to the same ServletContext.

this implies that if you have 2 clients A and B (each has his own session) it is possible for user B to access attribute a that belongs to client A's.


client A and B can access attribute a,but they will get the value according to their session

please let me know any further clarification
 
Musab Al-Rawi
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but they will get the value according to their session

so that attribute is not reachable for both clients from within the same session.


check the spec's, as the post I referred earlier indicates:
"... the same ServletContext and handles a request identified as being a part of the same session."
 
Amruth Puppala
Ranch Hand
Posts: 295
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi seetharaman,

please remmember both has theire own session
In client A session.setAttribute("keyX","valueB");
In client B can we access keyX attribute?
[ July 29, 2008: Message edited by: Chintu sirivennela ]
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Chintu sirivennela:
In client B can we access keyX attribute?


yes . you can//i think ,i mention above clearly
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i think we need the bartender help
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic