• 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:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • 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);
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!