Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Marcus green mock questinos doubt?

 
gurpeet singh
Ranch Hand
Posts: 924
1
Fedora Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
following is question no. 65 of test 1 from marcus green mock test


Marks: 1
Which of the following statements are true?
Choose at least one answer.
A. A session will always be invalidated if a user shuts down their browser
B. A session will always be invalidated if the servlet container restarts
C. A session can be invalidated by calling the invalidate method of the HttpSession class
D. A session can be invalidated by calling the delete method of the HttpSession class
E. A session cannot be invalidated via programmer code
F. The session timeout interval can be specified in the deployment descriptor


the correct answer according to the site is C and F.

i think the answer should also include E and B.

but my real question is regarding optino B. if a container restarts will always the sessions by invalidated ? sessions are after all Objects and if server restarts they are invalidated. right ? unless some container stores them on database. please help

regards
gurpreet
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2450
96
Android Chrome Eclipse IDE
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Answer E is not true because of answer C (HttpSession.invalidate()) can be used to programmatically invalidate the Session)

Answer B is questionable, because the specs don't say anything about it. There is no explicit requirement that a Session object should survive a container crash however many web-containers offer that functionality. If you would have to answer the question with the specs in mind you would say: yes is it a correct answer.

Regards,
Frits
 
Sebastien French
Greenhorn
Posts: 26
Firefox Browser Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I think F should be correct, you can specify timeout in DD like that :



 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2450
96
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

the correct answer according to the site is C and F.

i think the answer should also include E and B.


Yes: C and F are also correct, we were only discussing whether to include E and B as correct answers

Regards,
Frits
 
Sebastien French
Greenhorn
Posts: 26
Firefox Browser Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I read too quicly the question, sorry :'(
 
gurpeet singh
Ranch Hand
Posts: 924
1
Fedora Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks alot Fritz for clearing doubts regarding option B

for option E i was reading cannot as can
 
Ankit Gareta
Ranch Hand
Posts: 67
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

Sessions are stored depends on web-browsers(means stored in cookies depends on web-browser),
So i think when the servlet container restarts doesn't make a signal to invalidate session value that stored , so i think the answer B is wrong.
But i don't read the spec till.

wrong me if i wrong.
Thanks,
Ankit
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2450
96
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ankit,

The Session object lives on the Server, the reference to a Session object lives in the browser (in a Cookie). If you kill the browser, the reference is lost, but the Session object is still on the server.

If you restart the server, the Session object will be destroyed. The Servlet-container builders, however, can provide a service that will recreate the Session object after a shutdown/restart of the server (e.g. by serializing and de-serializing the Session objects). As the specifications don't require that a Session object should be recreated after a shutdown/restart of the server you can conclude that B is correct

Regards,
Frits
 
Ankit Gareta
Ranch Hand
Posts: 67
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Frits,
Frits Walraven wrote:Hi Ankit,

The Session object lives on the Server, the reference to a Session object lives in the browser (in a Cookie). If you kill the browser, the reference is lost, but the Session object is still on the server.

If you restart the server, the Session object will be destroyed. The Servlet-container builders, however, can provide a service that will recreate the Session object after a shutdown/restart of the server (e.g. by serializing and de-serializing the Session objects). As the specifications don't require that a Session object should be recreated after a shutdown/restart of the server you can conclude that B is correct

Regards,
Frits

Thanks for you reply, So session object lives on server, so there is two reference of the session, one is in server and another is in browser's cookies.
so if i cleared all the cookies of the browser, that will not affect on session object that are stored in server, right ? session stored in server can be deleted only by invalidate method of HTTPSession while server is running.

Thanks,
Ankit
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2450
96
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so if i cleared all the cookies of the browser, that will not affect on session object that are stored in server, right ?

Correct.
session stored in server can be deleted only by invalidate method of HTTPSession while server is running.

Or by the means of a time-out (when it occurs the server will remove the Session object)
- either by setting the global session time-out value in the web.xml (<session-config><session-timeout>30</session-timeout></session-config>) or
- by setting a time-out value on a specific Session object (setMaxInactiveInterval(int interval).

Regards,
Frits
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic