as far as i know... session object lives from the moment that the user logins till logout which invalidates the session. next, request object is only instantiated whenever the user submits a form. and request object is short-lived..
and request object is heavier than the session object since a request contains session object.
am i right to say that?
Vijayendra V Rao
Ranch Hand
Joined: Jul 04, 2004
Posts: 195
posted
0
and request object is heavier than the session object since a request contains session object.[/QB]
Now what exactly do you mean by "heavier" objects? Do you mean with respect to memory or something else?
Vijayendra <br /> <br />"The harder you train in peace, the lesser you bleed in war"
Sachin Roham
Greenhorn
Joined: Aug 03, 2004
Posts: 19
posted
0
hi Hardy, If u mean that "request" object is heavier than "session" because the former contains the latter, then i object. Cause in java no object can contain another object, it can contain only the reference of another object. And a session object is more heavier in a sense, because the container has to do a lot of work to mantain the various sessions, it has to maintain a kind of hashmap to store the session object with the corresponding Session-ID...and much more.
-
Try my simulator
Jeroen Wenting
Ranch Hand
Joined: Oct 12, 2000
Posts: 5093
posted
0
A request object is created whenever a request arrives at the application server. A session object is created just once per session (at most).
The session is mainly a storehouse for information that should be maintained between requests, the request contains all information needed to handle it which is a lot.
42
Hardy Chou
Greenhorn
Joined: Jun 27, 2001
Posts: 27
posted
0
To Vijayendra V Rao, yes in respect of memory usage.
and processing the attribute values later in the POJO
which one is a better approach?
satish sathineni
Ranch Hand
Joined: May 03, 2004
Posts: 46
posted
0
Basic difference between the Request object and the Session object is the way user uses it..
Session object created by the user upon his requirement.
Request object is created by the webserver.
the reason Request object contains information about the individual request and the other information like ipaddress, whole lot of other things which the browser sends as the headers ...
where as Session on the other hand contains only the user defined objects which are specially used by the user ....
Vijayendra V Rao
Ranch Hand
Joined: Jul 04, 2004
Posts: 195
posted
0
Originally posted by satish sathineni:
where as Session on the other hand contains only the user defined objects which are specially used by the user ....
As far as I know, the session object is used by the servlet container to identify a user between requests. I don't think there are "user defined" objects and they are used by the user. The session is used by the servlet container for unique user identification. Please correct me if I am wrong
satish sathineni
Ranch Hand
Joined: May 03, 2004
Posts: 46
posted
0
As far as I know, the session object is used by the servlet container to identify a user between requests. I don't think there are "user defined" objects and they are used by the user. The session is used by the servlet container for unique user identification. Please correct me if I am wrong
Yes ur right Session is used by the server to uniquely identify the user. but why a programmer uses the session for writing some user specific code and stuff that applies.... from programming point of view i said session holds user said variables
Vijayendra V Rao
Ranch Hand
Joined: Jul 04, 2004
Posts: 195
posted
0
Originally posted by satish sathineni:
Yes ur right Session is used by the server to uniquely identify the user. but why a programmer uses the session for writing some user specific code and stuff that applies.... from programming point of view i said session holds user said variables
Ofcourse!
Maybe the word "user-specific" attributes would be more appropriate than "user-said" attributes. Thats all I wanted to say
Hugh Jamieson
Greenhorn
Joined: Dec 03, 2002
Posts: 8
posted
0
Originally posted by Hardy Usman: another question regarding design:
lets say i can get the session from servlet controller. is it wise to pass the session to POJO instead of passing the necessary values?
and processing the attribute values later in the POJO
which one is a better approach?
Hi, Hardy! I don't think I saw a good answer to your question, so here are my ten cents: If you pass the request -or- session object to your POJO, you will be forced to bind your POJO to those container classes, which will require those classes anytime you use your POJO. You are better off passing the individual parameters, giving your POJO a chance at better reusability.
I agree with Hugh, and would add that not only does passing the session bind your class to the servlet environment (as he pointed out), it also spreads implied knowledge into the class in that it will need to know the keys to use in order to obtain the attributes. Not a great way to do things.
Sadanand Murthy
Ranch Hand
Joined: Nov 26, 2003
Posts: 382
posted
0
Originally posted by satish sathineni:
Yes ur right Session is used by the server to uniquely identify the user. but why a programmer uses the session for writing some user specific code and stuff that applies.... from programming point of view i said session holds user said variables
You can add attributes to the request object also.
Ever Existing, Ever Conscious, Ever-new Bliss
Rene Smith
Greenhorn
Joined: Jun 10, 2004
Posts: 21
posted
0
I believe request is better to use than session when at all possible. You don't have to worry about clean up of the session, the request object is gone once the request is over - period.
Also - as far as storing information about the user - that's true - but it can also store more information than just user information. If an app is not carefully constructed it can store a lot of crap that could hang around in memory until the user terminates his session or until the session expires - which potentially can be alot of time.
So - please, please use request whenever possible. And, if you need to use sessions (which all interactive apps are going to need to do to some point) just ensure clean up. Just think of 10 session variables each with 100 row arraylists times 100 users - AHHHH.