Sunday, December 24, 2017

Difference between Parameter and Attribute

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.

2- Parameters are read only that is Servlet can not modify them.
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:
Waking for interview-





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

Java Functional Interface

Java Lambda expression Lambda expression came to enable to use functional programming feature in java. It provides the facility t...