Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between session.setAttribute and request.setAttribute?

Tags:

java

servlets

What's the difference between session.setAttribute and request.setAttribute?

like image 819
ThePhantom05 Avatar asked Jun 06 '13 20:06

ThePhantom05


2 Answers

The scope, session attribute live all the session and the request attribute only in a request

like image 133
DGomez Avatar answered Dec 01 '22 23:12

DGomez


Difference lies in the scope. Request-scoped attribute is visible only while current request is processed. Session attribute is persistent between several requests from the same user. Session support mechanisms may differ (the most widespread are cookie based), but all of them guarantee session attrigbute persistence until user's session stays the same.

like image 29
Jk1 Avatar answered Dec 02 '22 00:12

Jk1