Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Managing webapp session data/controller flow for multiple tabs

Tags:

I have a Java web application which stores some data in the session. The data in the session changes as the user interacts with the application (e.g. flow is managed by a controller, each controller has several form pages, on each form page some data is updated in the session and flow goes to the next form page).

The problem is that some users are opening more than one tab to the application, each tab with a different step in the flow. At this point data in the session is messed up since the tabs share the same session (app uses cookie managed sessions).

Telling the users to use different browsers to avoid sharing the same session id (e.g. one Firefox window and one IE window) is not an option since surely at some point somebody will forget to do this and instead use tabs, thus messing up their data.

Adding some verifications that detect that another flow is requested from another tab and display a message to the user saying this is not allowed is not an option either since it pisses of the users and we don't want that do we? :D

The fact is that using another tab is useful for the users because they are more efficient in what they use the application for, so I am keeping this option. But the question now is how best to manage the one session data for the more tabs?

What I thought of, was to have the controller generate a token when it starts the flow and pass this token to each form page which in turn sends it back to identify itself. If another tab requests the same controller action when there is an ongoing flow then generate another token and pass that around.

Basically, I want each flow to have a token and inside the session I won't just keep one set of data but have a set of data for each token and then match requests based on the token.

Now the problem is that this approach will need a lot of rewritings to the application and I was wondering if there is a best practice for managing such a situation or can someone suggest other approaches. I am open to ideas.

Have you encountered this situation? How did you handle it?

like image 1000
Gabriela Avatar asked Dec 18 '10 20:12

Gabriela


People also ask

How do I use different browser tabs in sessions?

Per default, there is no way to have different sessions in the same browser window. The sessions are always shared trough all tabs. If two different Sessions are enough, you could use a privat/incognito browser window. A other solution could be to use HTML 5 SessionStorage for your variables.

Is each tab a new session?

Every browser tab uses the same Session for a single domain. State within a browser tab can be managed or tracked using the URL (HTTP GET) or a form field (HTTP POST).


1 Answers

This is usually done by assigning a windowId for each tab/window and passing it on each request. Jsf supports this via orchestra. Spring mvc will support it in the next version.

I recently needed this for a simple case, so I implemented it myself. Took half an hour. However, my scope was very limited:

  • pass a windowId with each request, and return it back for the next request. The first time - generate it.
  • for any attribute you want to store in the session, put a Map<String, Object> where the key is the windowId
like image 150
Bozho Avatar answered Oct 09 '22 07:10

Bozho