1- Parameter represents data which is
received as part of request and store in ServletRequest
object by the Server.
Attributes represent information which is stored in the ServletRequest object by Servlet to share it with another servlet participate in the processing of same request.
Attributes represent information which is stored in the ServletRequest object by Servlet to share it with another servlet participate in the processing of same request.
2- Parameters are read only that is Servlet can not modify them.
Attribute are stored, read, remove and replaced by the Servlet.
Attribute are stored, read, remove and replaced by the Servlet.
3- Parameters represent data in String form whereas Attributes
represents data in object form.
Note:
Attributes are required only if multiple Servlet participate in the processing of request.
Real life example:
|
Let there
be two Servlet s1 and s2. Both of the Servlets participates in the processing
of a request. Servlet s1 does initial processing and shares its result with s2
which sends final response.
1.1- ServletRequest object is created and request data is stored as a parameter.
1.2- ServletResponse object is created to receive response.
1.3- Servlet s1 is asked to process request.
1.4- Servlet s1 reads request parameter, does it processing and store its result as attributes in SrevletRequest object.
1.5- Request is forwarded to Servlet s2.
1.6- Servlet s2 reads request parameters and attributes.
1.7- Servlet s2 applied processing logic and stores its result in ServletResponse object.
No comments:
Post a Comment