• Post Reply Bookmark Topic Watch Topic
  • New Topic

difference b/t session.setAttribute and request.setAttriute

 
Ghazala Islam
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am reading a MVC model web application ,in which somewhere they are using request.setAttribute and somewhere session.setAttribute,as far as i understand when you've to dispatch a request to another JSP,use request.setAttribute whereas in a class that is doing various operations like,loading data or saving data session.setAttribute is required?If not then whats the difference b/w two?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The major difference is in the lifetime of the two contexts. Since the request only "lives" for the duration of a single request/response cycle, any scoped variables placed onto that request will go out of scope when the response is sent to the client.

Session context, on the other hand, sticks around over multiple requests made from the same client.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!