wood burning stoves 2.0*
The moose likes JSP and the fly likes HTTP session Vs Request.getSession() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "HTTP session Vs Request.getSession()" Watch "HTTP session Vs Request.getSession()" New topic
Author

HTTP session Vs Request.getSession()

vikasids sharma
Ranch Hand

Joined: Aug 01, 2003
Posts: 157
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


Thanks
Vikas Sharma
SCJP(1.4)
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

Both are same provided the session has not already timed out.


Groovy
vikasids sharma
Ranch Hand

Joined: Aug 01, 2003
Posts: 157
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

Joined: Feb 27, 2002
Posts: 8919

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

Joined: Aug 01, 2003
Posts: 157
thanks Pradeep
Originally posted by Pradeep Bhat:
Sorry Vikas! Both the above are same.
Scott Duncan
Ranch Hand

Joined: Nov 01, 2002
Posts: 363
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);


No more rhymes! I mean it!<br /> <br />Does anybody want a peanut?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: HTTP session Vs Request.getSession()