• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Tabs within one browser share Session, but I want to capture close and time out event for each tab

 
Greenhorn
Posts: 12
Netbeans IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi friends!

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

Estillan
 
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Xu, I donot think you can capture the event related to Tabs. As tabs are the property of the browser and it shares the session data. So you cannot diff. events between tabs.

Regards,
Sunil
 
Estillan Xu
Greenhorn
Posts: 12
Netbeans IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Kumar,

Thanks for your reply.

Is it correct I have two options:

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?

Estillan
 
Ranch Hand
Posts: 312
MS IE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
xsunil kumar
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Devaki,

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.

Regards,
Sunil
 
Ranch Hand
Posts: 448
Eclipse IDE Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
See if the following link helps you:

http://stackoverflow.com/questions/368653/how-to-differ-sessions-in-browser-tabs
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have to ask: why do you need to subvert the session behaviour of the browser in this way?
 
Estillan Xu
Greenhorn
Posts: 12
Netbeans IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Sturrock wrote:I have to ask: why do you need to subvert the session behaviour of the browser in this way?



Hi Paul,

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. )

I hope this explanation is clear.

Estillan
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Estillan Xu
Greenhorn
Posts: 12
Netbeans IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For example, user may want to use Google Doc to open multiple files.
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Estillan Xu
Greenhorn
Posts: 12
Netbeans IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My application is written in Java Applet embedded in web page.
If user wants to open multiple files, multiple applet instance need to be loaded.
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But Applets are client side - what part does the Session play in that? (again - I may be being really stupid here - but this sounds like its more complex than it needs to be)
 
Estillan Xu
Greenhorn
Posts: 12
Netbeans IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm sorry. My bad. Maybe I didn't sketch it clearly.

The client is making http request to the server. The session is used here for two reasons:

1: to store client information at server side (in order to reduce the traffic and enhance the security).

2: for server to notice when client quit or inactive for a while.
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Estillan Xu
Greenhorn
Posts: 12
Netbeans IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What would this heart beat do?
 
reply
    Bookmark Topic Watch Topic
  • New Topic