Session per Browser Tab

Introduction

Session per browser tab means the pages on each browser tab are independent, not sharing session state, even if they're calling the same Action. This is achieved with interceptors and JavaScript library run in each JSP page.

Setup

The browserTab.js library works by setting the window.name DOM property as the tab id and comparing any exisitng tab id with what the Action believes it is. Thus, it's best to use the JavaScript library in a JSP page called before any Action expecting session per browser tab data. This can be done in a welcome or login page. If not, the Action is reloaded.

JSP

For each JSP page, link to browserTab.js library, such as below. It will automatically run code.

<HEAD>

  ...

  <SCRIPT TYPE="text/javascript" SRC="<s:url value="/js/browserTab2.js" />"></SCRIPT>

  ...

</HEAD>

Other Requirements

If a user right-clicks a link and opens it in a new tab, they expect the new page to be unaffected by pages in other tabs. This requires cloning session data and if data is not Cloneable or have a deep copy constructor, different tabs may refer to the same objects. However, users typically find a results list and open links to detail pages in new tabs. As lists are shallow copied, leading the list page and detail pages having their own lists, it's usually possible to get away with lack of deep copying.

Also, Actions must directly or indirectly extend AbstractActionSupport (which all Template Actions in this library do) or otherwise implement BrowserTabAware2.

Usage

For session per browser tab, Actions should call getBrowserTabSession, which returns a wrapper around the servlet session that implements HttpSession like a servlet session. The standard HttpSession setter functions, such as setAttribute, actually sets per-tab specific data whilst getAttribute reads from per-tab or shared session data. Use setSharedAttribute for setting shared session data. See BrowserTabSession.