GSNA · Question #89
Which of the following statements about invalidating a session is true?
The correct answer is C. A session can be invalidated programmatically as well as using the deployment descriptor. An existing session can be invalidated in the following two ways: Setting timeout in the deployment descriptor: This can be done by specifying timeout between the <session-timeout> tags as follows: <session-config> <session-timeout> 10 </session-timeout> </session-config> This…
Question
Which of the following statements about invalidating a session is true?
Options
- AThe getCreationTime() method can be called on an invalidated session.
- BThe invalidate() method belongs to the HttpServletRequest interface.
- CA session can be invalidated programmatically as well as using the deployment descriptor.
- DThe getAttribute(String name) method throws an IllegalArgumentException if called on an
How the community answered
(29 responses)- A17% (5)
- B3% (1)
- C72% (21)
- D7% (2)
Explanation
An existing session can be invalidated in the following two ways: Setting timeout in the deployment descriptor: This can be done by specifying timeout between the <session-timeout> tags as follows: <session-config> <session-timeout> 10 </session-timeout> </session-config> This will set the time for session timeout to be ten minutes. Setting timeout programmatically: This will set the timeout for a specific session. The syntax for setting the timeout programmatically session.setMaxInactiveInterval(10*60) In this method, the timeout is specified in seconds. Hence, this will set the time for the session timeout to be ten minutes. Answer: A is incorrect. The getCreationTime() method returns the time when the session was created. The time is measured in milliseconds since midnight January 1, 1970. This method throws an IllegalStateException if it is called on an invalidated session. Answer: D is incorrect. The getAttribute(String name) method of the HttpSession interface returns the value of the named attribute as an object. It returns a null value if no attribute with the given name is bound to the session. This method throws an IllegalStateException if it is called on an invalidated session. Answer: B is incorrect. The invalidate() method belongs to the HttpSession interface.
Topics
Community Discussion
No community discussion yet for this question.