Page: 8
Unit- 4: Session Management
Q 20. As a convenience feature, your web pages include an Ajax request every five minutes to a special servlet that monitors the age of the user's session. The client-side JavaScript that handles the Ajax callback displays a message on the screen as the session ages. The Ajax call does NOT pass any cookies, but it passes the session ID in a request parameter called sessionID. In addition, assume that your webapp keeps a hashmap of session objects by the ID. Here is a partial implementation of this servlet: 10. public class SessionAgeServlet extends HttpServlet { 11. public void service(HttpServletRequest request, HttpServletResponse) throws IOException { 12. String sessionID = request.getParameter("sessionID"); 13. HttpSession session = getSession(sessionID); 14. long age = // your code here 15. response.getWriter().print(age); 16. } ... // more code here 47. } Which code snippet on line 14, will determine the age of the session? A. session.getMaxInactiveInterval(); B. session.getLastAccessed().getTime() - session.getCreationTime().getTime(); C. session.getLastAccessedTime().getTime() - session.getCreationTime().getTime(); D. session.getLastAccessed() - session.getCreationTime(); E. session.getMaxInactiveInterval() - session.getCreationTime(); F. session.getLastAccessedTime() - session.getCreationTime(); Answer: F Q21. Which statement is true about web container session management? A. Access to session-scoped attributes is guaranteed to be thread-safe by the web container. B. To activate URL rewriting, the developer must use the HttpServletResponse. setURLRewriting method. C. If the web application uses HTTPS, then the web container may use the data on the HTTPS request stream to identify the client. D. The JSESSIONID cookie is stored permanently on the client so that a user may return to the web application and the web container will rejoin that session. Answer: C Q22. Given an HttpServletRequest request and an HttpServletResponse response: 41. HttpSession session = null; 42. // insert code here 43. if(session == null) { 44. // do something if session does not exist 45. } else { 46. // do something if session exists 47. } To implement the design intent, which statement must be inserted at line 42? A. session = response.getSession(); B. session = request.getSession(); C. session = request.getSession(true); D. session = request.getSession(false); E. session = request.getSession("jsessionid"); Answer: D
Page: 8
1
2
3
4
5
6
7
8
9
10
|