• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Ron McLeod
  • Tim Moores
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Vijitha Kumara

HTTP session Vs Request.getSession()  RSS feed

 
Ranch Hand
Posts: 157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all
can anybody clarify me the difference between using HTTPSession session.setAttribute("",""), and request.getSession().setAttribute("","");
1. How the scope of these two session object are different?
thanks in advance
Vikas
 
Ranch Hand
Posts: 8934
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Both are same provided the session has not already timed out.
 
vikasids sharma
Ranch Hand
Posts: 157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By saying that
"Both are same provided the session has not already timed out."
Do we mean if session times out , we get different types of exception depending upon the classes(HTTPSession and Request) of session object?
 
Pradeep bhatt
Ranch Hand
Posts: 8934
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry Vikas! Both the above are same.
Session is obtained by calling request.getSession().
So session .setAttribute(..) is same as request.getSession().setAttribute(..)
 
vikasids sharma
Ranch Hand
Posts: 157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks Pradeep

Originally posted by Pradeep Bhat:
Sorry Vikas! Both the above are same.

 
Ranch Hand
Posts: 365
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
request.getSession() returns a session if one exists or creates a new one if it does not. It is the same as calling request.getSession(true). Since retrieving a session goes like this:
HttpSession session = request.getSession();
or:
HttpSession session = request.getSession(true);
Then:
HttpSession session = request.getSession();
session.setAttribute(Object a, Object b);
would have to be the same as:
request.getSession().setAttribute(Object a, Object b);
or:
request.getSession(true).setAttribute(Object a, Object b);
 
Hug your destiny! And hug this tiny ad:
global solutions you can do at home or in your backyard
https://www.kickstarter.com/projects/paulwheaton/better-world-boo
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!