Win a copy of Hands On Software Engineering with Python this week in the Jython/Python forum!
  • 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
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
Bartenders:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

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);
 
The only taste of success some people get is to take a bite out of you. Or this tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!