1Z0-900 · Question #61
Your web application requires logic to remember items that a user placed into a shopping cart. Which two mechanisms should you use to associate that information with the user? (Choose two.)
C (HttpSession) and D (a database) are the correct answers. HttpSession objects store user-specific data server-side and are automatically associated with a particular user via a session ID cookie. They are the standard mechanism for tracking transient, per-user state like cart…
Question
Your web application requires logic to remember items that a user placed into a shopping cart. Which two mechanisms should you use to associate that information with the user? (Choose two.)
Options
- AHttpServletResponse objects
- BServletContext objects
- CHttpSession objects
- Da database
Explanation
C (HttpSession) and D (a database) are the correct answers.
HttpSession objects store user-specific data server-side and are automatically associated with a particular user via a session ID cookie. They are the standard mechanism for tracking transient, per-user state like cart contents within a single browsing session. A database complements this by persisting cart data beyond the session - essential when users log in from different browsers or return later.
A is wrong - HttpServletResponse is the outgoing HTTP response object used to send data to the client; it holds no user state.
B is wrong - ServletContext is application-wide scope shared across all users simultaneously, making it unsuitable for user-specific data like individual carts.
Memory tip: Think of scope levels - ServletContext is the "whole mall" (everyone), HttpSession is the "shopping cart" (one person, one visit), and a database is the "saved wishlist" (one person, any visit). Match the scope to the need.
Topics
Community Discussion
No community discussion yet for this question.