Page: 5
Unit- 4: Session Management
Q11. Users of your web application have requested that they should be able to set the duration of their sessions. So for example, one user might want a webapp to stay connected for an hour rather than the webapp's default of fifteen minutes; another user might want to stay connected for a whole day. Furthermore, you have a special login servlet that performs user authentication and retrieves the User object from the database. You want to augment this code to set up the user's specified session duration. Which code snippet in the login servlet will accomplish this goal? A. User user = // retrieve the User object from the database session.setDurationInterval(user.getSessionDuration()); B. User user = // retrieve the User object from the database session.setMaxDuration(user.getSessionDuration()); C. User user = // retrieve the User object from the database session.setInactiveInterval(user.getSessionDuration()); D. User user = // retrieve the User object from the database session.setDuration(user.getSessionDuration()); E. User user = // retrieve the User object from the database session.setMaxInactiveInterval(user.getSessionDuration()); F. User user = // retrieve the User object from the database session.setMaxDurationInterval(user.getSessionDuration()); Answer: E Q12. Which two classes or interfaces provide a getSession method? (Choose two.) A. javax.servlet.http.HttpServletRequest B. javax.servlet.http.HttpSessionContext C. javax.servlet.http.HttpServletResponse D. javax.servlet.http.HttpSessionBindingEvent E. javax.servlet.http.HttpSessionAttributeEvent Answer: A, D Q13.You have built a web application that you license to small businesses. The webapp uses a context parameter, called licenseExtension, which enables certain advanced features based on your client's license package. When a client pays for a specific service, you provide them with a license extension key that they insert into the <context-param> of the deployment descriptor. Not every client will have this context parameter so you need to create a context listener to set up a default value in the licenseExtension parameter. Which code snippet will accomplish this goal? A. You cannot do this because context parameters CANNOT be altered programmatically. B. String ext = context.getParameter('licenseExtension'); if ( ext == null ) { context.setParameter('licenseExtension', DEFAULT); } C. String ext = context.getAttribute('licenseExtension'); if ( ext == null ) { context.setAttribute('licenseExtension', DEFAULT); } D. String ext = context.getInitParameter('licenseExtension'); if ( ext == null ) { context.resetInitParameter('licenseExtension', DEFAULT); } E. String ext = context.getInitParameter('licenseExtension'); if ( ext == null ) { context.setInitParameter('licenseExtension', DEFAULT); } Answer: A
Page: 5
1
2
3
4
5
6
7
8
9
10
|