I just learned that multiple tabs within one browser window share the same http session, therefore I need to make some changes on my projects.
My client side is Applet loading in a html page, and server is Servlet.
Now my questions are:
1: Is it possible for me to capture tab close event at server side? Something similar to session terminate.
2: Is it possible for me to assign a max-inactive-interval to one tab and capture the time-out event?
3: Can I ensure if the session is still alive, the tab closing event captured by client, can be sent to server successfully?
I guess if I'm able to solve above problems, I don't need to use URL encoding (I'm not familiar with that either) to make the server consider two tabs as two sessions.
Thanks in advance! It's my first time to post something
My first program "Hello World" was in 1997, but until now that's the only thing I know.
either implement the tab time-out event by myself, for example, make the client sending heart beat message to the server, and server update its status;
or try to find the solution to make each tab gets one session for its own?
I believe, configuring a session timeout value in your web-application can solve this issue. However, if you want to keep the session alive, you can use AJAX to send heart beat signals back to the server to update the session timeout interval.
Not many get the right opportunity !
Joined: Dec 14, 2009
What ever solution you have suggested is applicable to entire session. It is not related to Your tab event. Session timeout in web application is valid for all tabs. Ajax call will increase the session but it again for all tags.
@Estillan - i am not very much sure how you can control tab event with Server. You can write your own events that will be fired on closing the Tab but again it will be common to all open tabs from Server point of view.
Tabs are just replica of main window. It shares same data with same session id.
If you get any answer, please post it. It will be useful for other's.
Paul Sturrock wrote:I have to ask: why do you need to subvert the session behaviour of the browser in this way?
You can imagine that each tab is one instance of my application, and user may want to open several instances of the application. Each instance corresponds to one particular entry in the Session. I want to capture the time-out (the tab crash but session is till alive... is it possible? ) and terminate (user close the tab) event to let server clear up that entry and do other actions.
That's why initially I have no idea multiple tabs belong to one session, I was trying to use http session API. Of course another solution is to force user open a new browser window each time in order to have a new session (that's not always true, for Chrome, even multiple windows belong to one session. )
Yes Estillan, that makes sense. But it does sounds like you are making work for yourself. Do users actually need to open many instances of the application? Its just I can think of several good reasons why you probably wouldn't want this behaviour.
Not sure why this would need you to open multiple instances of something, just multiple docs in one application. Am I missing something?
Consider the other side, if a user is using two concurrent instances of one database backed application (for example) and working on closely related or the same data through both they will run the risk of either getting lost updates caused or optimistic locking issues they've caused. Its an extra risk to (as far as I can see) no gain.
That's all OK. But why a distinct session per Applet? Would it not be easier to uniquely identify each Applet instance and partition session data based on this? Is that not a bit easier than trying to subvert or workaround expected browser behaviour?
True. Back to my initial question, the reason why I'm trying to "assign" session for each Applet is that I want to use HTTP Session API such as "setMaxInactiveInterval", "SessionBindingListener", etc. to monitor the behavior of each Applet. However, if I cannot achieve this, I will implement those function to handle each Applet by myself then.
For example, I'll use "heart-beat" to detect Applet time-out.