You can store the data in different container objects to access later, depending on the requirement.
These objects are called "scoped objects.
You can store the data in the required scope as an attribute.
An attribute is a name-value pair.
The name of an attribute is of type String.
The value of an attribute is of type "object.
Attributes are read-write, i.e., you have to store the attributes so that you can collect them later.
You can use the following methods to manage the attributes:
void setAttribute(String,Object)
Object getAttribute(String)
void removeAttribute(String)
Enumeration getAttributeNames()
There are 3 scopes in Servlet.
1. Request Scope
2. Session Scope
3. Context Scope
When the data is stored in the HttpServletRequest object, the scope of that data is the request scope.
The data from the request scope can be accessed by that single user in that request only before sending the response to the client.
When the data is stored in the HttpSession object, then the scope of that data is session scope.
The data from session scope can be accessed by a single user across multiple requests (within the same session).
When the data is stored in the ServletContext object, then the scope of that data is context scope.
The data from context scope can be accessed by multiple users across multiple requests.
There are 4 scopes in JSP.
1. Page Scope
2. Request Scope
3. Session Scope
4. Application Scope
The data from page scope can only be accessed within the same JSP.
When the data is stored in the HttpServletRequest object, the scope of that data is the request scope.
The data from the request scope can be accessed by that single user in that request only before sending the response to the client.
When the data is stored in the HttpSession object, then the scope of that data is session scope.
The data from session scope can be accessed by a single user across multiple requests (within the same session).
When the data is stored in the ServletContext object, then the scope of that data is context scope.
The data from context or application scope can be accessed by multiple users across multiple requests.