if you use httpServletRequest.setAttribute (); then the attribute will be bound to this request object,
and in httpServletSession.setAttribute(); attr will be attached. in session.
therefore, if you want the data region of this data to be used in a session , or if you need this region of data for a request only, use request
Example:
The username of the logged in user must be shared by the session, so save it to session
while, the error message that you give the user when considering the authentication error case, it is necessary for this request, only after that we do not need it, so keep it in request
Jigar joshi
source share