Page: 7
Unit- 4: Session Management
Q17. Given an HttpServletRequest request: 22. String id = request.getParameter("jsessionid"); 23. // insert code here 24. String name = (String) session.getAttribute("name"); Which three can be placed at line 23 to retrieve an existing HttpSession object? (Choose three.) A. HttpSession session = request.getSession(); B. HttpSession session = request.getSession(id); C. HttpSession session = request.getSession(true); D. HttpSession session = request.getSession(false); E. HttpSession session = request.getSession("jsessionid"); Answer: A, C, D Q18. A developer for the company web site has been told that users may turn off cookie support in their browsers. What must the developer do to ensure that these customers can still use the web application? A. The developer must ensure that every URL is properly encoded using the appropriate URL rewriting APIs. B. The developer must provide an alternate mechanism for managing sessions and abandon the HttpSession mechanism entirely. C. The developer can ignore this issue. Web containers are required to support automatic URL rewriting when cookies are not supported. D. The developer must add the string ?id=<sessionid> to the end of every URL to ensure that the conversation with the browser can continue. Answer: A Q19. Given the definition of MyObject and that an instance of MyObject is bound as a session attribute: 8. package com.example; 9. public class MyObject implements 10. javax.servlet.http.HttpSessionBindingListener { 11. // class body code here 12. } Which is true? A. Only a single instance of MyObject may exist within a session. B. The unbound method of the MyObject instance is called when the session to which it is bound times out. C. The com.example.MyObject must be declared as a servlet event listener in the web application deployment descriptor. D. The valueUnbound method of the MyObject instance is called when the session to which it is bound times out. Answer: D
Page: 7
1
2
3
4
5
6
7
8
9
10
|