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.)
Click on the arrows to vote for the correct answer
A. B. C. D.BC.
To remember the items that a user placed into a shopping cart, you need to associate that information with the user in a persistent way. In Java web applications, there are several mechanisms available to achieve this, but the two most common ones are using HttpSession
objects or a database.
HttpSession
objects: A HttpSession
is an object that represents a user-specific context between the web client and the server. It is a server-side mechanism that allows you to store and retrieve information about a user's interaction with your web application across multiple requests. You can use HttpSession
objects to store information about the items that a user places into a shopping cart, and retrieve that information when the user revisits your web application.Here's how you can use HttpSession
objects to remember the items in a shopping cart:
HttpSession
object.HttpSession
object and display it to the user.Here's how you can use a database to remember the items in a shopping cart:
Using HttpSession
objects is a simpler approach and doesn't require a separate database. However, it has limitations on the amount of data that can be stored, and the data is lost when the HttpSession
expires. Using a database provides a more robust and scalable solution, but it requires more setup and maintenance.