aspose file tools*
The moose likes Servlets and the fly likes URGENT DOUBT 3--- SESSION HANDLING Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "URGENT DOUBT 3--- SESSION HANDLING" Watch "URGENT DOUBT 3--- SESSION HANDLING" New topic
Author

URGENT DOUBT 3--- SESSION HANDLING

sanjay sawant
Greenhorn

Joined: Mar 15, 2002
Posts: 5
From Vel's Notes:
1.2.given a scenario, state whether a session object will be invalidated
1.2.1.ideally, a session would be invalidated as soon as the user closed his browser, browsed to a different site, or stepped away from his desk. Unfortunately, there’s no way for a server to detect any of these events.
Can someone please explain me 1.2.1.
I am confused.
gautam shah
Ranch Hand

Joined: Oct 29, 2000
Posts: 72
Originally posted by sanjay sawant:
From Vel's Notes:
1.2.given a scenario, state whether a session object will be invalidated
1.2.1.ideally, a session would be invalidated as soon as the user closed his browser, browsed to a different site, or stepped away from his desk. Unfortunately, there’s no way for a server to detect any of these events.
Can someone please explain me 1.2.1.
I am confused.

as soon as the user closed his browser-->
this situtaion can be detected in IE with the help of javascript. so we can easily invalidate the session. don't know abt other browsers.
browsed to a different site---> this situation can be detected in IE and NN both so we can easily invalidate the session if we want.don't know abt other browsers.
stepped away from his desk---> :roll:
Gagan Indus
Ranch Hand

Joined: Feb 28, 2001
Posts: 346
Gautam
Alright we can capture all those browser-window event with javascript on client-side , but in this case these events are interest of server-only , coz that is where actual session is being maintained.
is there a way you can communicate these events to server ? one may think yes , with javascript send info over HTTP but for that u will need to open another window ! or acces other URL etc etc .
And then these are just few of the 'ideal' conditions , you cant build 'trap' for all such things occuring on the client side
So much better way is to use 'timeouts' at server-side , which is what a web-container like tomcat/resin does


Gagan (/^_^\) SCJP2 SCWCD IBM486 <br />Die-hard JavaMonk -- little Java a day, keeps you going.<br /><a href="http://www.objectfirst.com/blog" target="_blank" rel="nofollow">My Blog</a>
gautam shah
Ranch Hand

Joined: Oct 29, 2000
Posts: 72
Originally posted by Gagan Indus:
Gautam
Alright we can capture all those browser-window event with javascript on client-side , but in this case these events are interest of server-only , coz that is where actual session is being maintained.
is there a way you can communicate these events to server ? one may think yes , with javascript send info over HTTP but for that u will need to open another window ! or acces other URL etc etc .
And then these are just few of the 'ideal' conditions , you cant build 'trap' for all such things occuring on the client side
So much better way is to use 'timeouts' at server-side , which is what a web-container like tomcat/resin does

Hi Gagan
what i had said abt both situation is a perfectly working solution implemented by me . offcourse i have to follow a url in that case but didn't need to open a additional browser window .according to me every http request recieved by server is an "event" after recieving of that, server starts to perform an action on basis of that. ya a good understanding of http session is required there.
in this case i have used javascript to "dispatchEvent".
using timeouts is entirely different thing then that.
and above all client requirement satisfication is must to get the salary on 7th.

William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12803
    
    5
You can't rely on a Javascript solution - suppose the user's connection gets dropped.
Bill
Gagan Indus
Ranch Hand

Joined: Feb 28, 2001
Posts: 346
Hi Gaurav
I have no doubt that the solution you recommended/implemented is working , i havent even raised a question about that .
Alright if we may please we can always write javascript and all to do so
( a javascript which ll capture the browser closing window event , it will invoke a servlet at the server which ll call the session.invalidate() , this is all it takes )
But then you seem to be missing a point here ,
The discussion above is about the automatic session-management facilites provided by all web-containers implemented according to JSR specs and NOT the hand-coded session-management
If you may choose you can even skip all the session-management facilties already built-into the servlet framework , and code your own from scratch , or extend them the way you like .
The web-container manages session primarly using cookies/url-rewriting ( it inserts the jsessionid for us right ? ) , but it do NOT provide any middle-tier callbacks on :
-closing of client window
-client moving to another website
-etc etc
Instead the web-containers use timeouts.
And ,these are just few of the conditions , you cant code callbacks for all such conditions even if you choose to do so. Lets says the clients connections breaks down without warning , surely we cant do any sort of 'callback' in this case. Here 'timeouts' shine.

Never re-invent the wheel ! especailly if you like to get your salary before 7th
Gagan Indus
Ranch Hand

Joined: Feb 28, 2001
Posts: 346
Oh i meant Gautam , NOT Gaurav .. :roll:
and yes William yer right we absolutely cant reply on javascript ( it isnt even supported as-is by all client )
gautam shah
Ranch Hand

Joined: Oct 29, 2000
Posts: 72
Originally posted by Gagan Indus:
Oh i meant Gautam , NOT Gaurav .. :roll:
and yes William yer right we absolutely cant reply on javascript ( it isnt even supported as-is by all client )

both of u r right. but some times it could be happened that ur server may wish to not to invalidate the session after specified time out.
then what only we can do is to just poke our hands in side the server and after searching our session
we should pray in front of that
" Ki Bhai mere ab to logout ho ja"
and till this time i am getting my salary on or before 7th just because of this spirit i think.
"Aur Aage bhagwan malik"
Gagan Indus
Ranch Hand

Joined: Feb 28, 2001
Posts: 346
LOL Gautum....
i feed my web-server well , so it do not play games like those with me ..
Translation Side-bar
" Ki Bhai mere ab to logout ho ja"
-->
Hey man please do logout now
"Aur Aage bhagwan malik"
-->
Future is in God's hands
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: URGENT DOUBT 3--- SESSION HANDLING