Am having a problem with session which is when in my web application different users are logged in then the same session is shared across multi tabs. Problem is i track single session in a browser to perform such process. Is there any possible way to keep session for tabs in JSP & Servlet. I can't invalidate session when duplicate or other user's logged into same application. Am stuck with this.
Asked
Active
Viewed 4,045 times
1 Answers
2
The server (where your jsp/servlet lives) is generally not in a position to tell if a link is opened in the same window or a new tab/window; that is unless of course the client (in this case web browser) tells it. Simply put; some client side code will do.
You could use the HTML5 window.sessionStorage object. A new instance of this object is created for each tab/window. Therefore generate a random id and save in session Storage per Browser Tab. Then each browser tab has his own Id. Communicate this id to the server...
See this answer by Gonzalo Galloti
Hope this helps
-
Could you give a short example how to pass in the tab id to the the server, please ? Via a hidden field or any other way ? The problem is that I set a value on the request in a java class (still Struts 1) and am able to get it in the displayed JSP. Then how to proceed to be able to get this tab ID in no matter which action class ? Thank you – belgoros Jul 25 '17 at 14:22
-
I tried as follows in a JSP `sessionStorage.setItem('country', '<%= country %>');`, but as far as I know it will work on the client-side only. That's why when I tried t get it later in a Action class as follows: `request.getSession().getAttribute("country")` it didn't work :(. – belgoros Jul 25 '17 at 14:23