Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Related to Session and Request objects

 
Sriram Sharma
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We fetch the session object from the request object.
Then what is the difference between request and session?
Why cant I use the request itself instead of session?
Is it that session can be fetched from request object only? Or is there any other way to get the session object?
Somebody please explain.

Regards,
Sriram
 
Nishan Patel
Ranch Hand
Posts: 689
Eclipse IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi,

yes, you are right session retrieval from request object. But you have to read about variable scope. The request and session are two different scope.

Request scope basically use for particular request. while session scope available through out web application. so which variable set as session scope you can access any part of request and therefor you have to access session scope form request object.

 
Sriram Sharma
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Nishan,

I am still not able to get the complete picture.
I am unable to get the exact meaning of the statement "while session scope available through out web application. so which variable set as session scope you can access any part of request and therefor you have to access session scope form request object." :-(

Can somebody help me out in understanding the session and request scope and also about session and request objects?

Regards,
Sriram

 
Nishan Patel
Ranch Hand
Posts: 689
Eclipse IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi,

while session scope available through out web application. so which variable set as session scope you can access any part of request and therefor you have to access session scope form request object


what I mean to say, when you set any variable using session you can you can use this variable at any place of your web application. That means at any request of your web application. Session available for you and for your web application at any time and at any place. While when you use request.setAttribute("user", "Nishan"); then that user variable available only that particular request. After that request if you use that user attribute that scope of user lost and you can not access that variable. While instead of if you use session then after second request that user object available for you..

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic