File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Estillan Xu
Greenhorn
Posts: 12
Java Netbeans IDE Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
xsunil kumar
Ranch Hand
Posts: 139
  • 0
  • Mark post as helpful
  • send pies
  • 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
Java Netbeans IDE Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
Madhan Sundararajan Devaki
Ranch Hand
Posts: 312
Java MS IE
  • 0
  • Mark post as helpful
  • send pies
  • 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: 139
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
Sunny Bhandari
Ranch Hand
Posts: 448
Eclipse IDE Firefox Browser Tomcat Server
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • 0
  • Mark post as helpful
  • send pies
  • 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
Java Netbeans IDE Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • 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
Eclipse IDE Hibernate Java
  • 0
  • Mark post as helpful
  • send pies
  • 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
Java Netbeans IDE Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For example, user may want to use Google Doc to open multiple files.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • 0
  • Mark post as helpful
  • send pies
  • 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
Java Netbeans IDE Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • 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
Eclipse IDE Hibernate Java
  • 0
  • Mark post as helpful
  • send pies
  • 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
Java Netbeans IDE Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • 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
Eclipse IDE Hibernate Java
  • 0
  • Mark post as helpful
  • send pies
  • 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
Java Netbeans IDE Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • 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
Eclipse IDE Hibernate Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What would this heart beat do?
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic