JBridge

JBridge: Certification Question Of The Day

JBridge Home >> Certification Questions >> Question for Thursday 8th May 2003 Thursday 8th May 2003

From the list below, identify legitimate ways to impose a 30 minute session timeout. (2 correct answers)



A request.invalidateSession(1800); (request is an instance of HttpServletRequest)
B session.invalidate(30); (session is an instance of HttpSession)
C In web.xml:
<session-config>
	<session-timeout>30</session-timeout>
</session-config>

D In web.xml:
<servlet>
	<servlet-name>MyServlet</servlet-name>
	<servlet-class>uk.co.jbridge.servlet.MyServlet</servlet-class>
	<servlet-session-timeout>30</servlet-session-timeout>
</servlet>

E session.setMaxInactiveInterval(1800); (sesson is an instance of HttpSession)
F session.setMaxInactiveInterval(30); (session is an instance of HttpSession)
G In web.xml:
<session-config>
	<session-timeout>1800</session-timeout>
</session-config>

Page down for the answer...











































The Answer

The correct answers are C and E. You can set a session to timeout using the element in web.xml, setting the time in minutes. You can also set the session timeout using the HttpSession method setMaxInactiveInterval – though this time you are dealing in seconds.
Answer A is completely made up.
In answer B, there is an invalidate() method in HttpSession – but it doesn’t take any parameter representing time or anything else. When this method is called, the session is immediately invalidated.
Answer D tries to persuade you that there is a way of configuring an individual servlet from web.xml to dictate session timeout. There is not.
Answer F is similar to correct answer E – but the timeout will be set to 30 seconds, not 30 minutes.
Answer G is similar to correct answer C – but the timeout will be set to 30 hours, not 30 minutes.


EMail: dbridgewater@jbridge.co.uk
Phone: +44 (0)1943 877414
Fax: +44 (0)1943 877414
Mail: David Bridgewater, Willow Dene, Bradford Road, Menston, Ilkley, West Yorkshire, LS29 6ED, UK
Copyright © 2003 David Bridgewater. All rights reserved.