The request attribute is only available for the lifetime of the request object. filters, servlet, jsp, include, forward uses the same request object. Upon completion of the request, the request object is destroyed.
While session attributes are available until the end of the session or until the browser closes. Therefore, the difference lies in the area.
For example, a stream, for example page1-> page2-> page3-> page4. session.setAttribute will make the key available on all pages. But if we use request.setAttribute on page 2, then only page3 can get the key value set on page2.
request.setAttribute() can help you get rid of hidden fields.
source share