Manage multiple sessions at the same time

In a specific scenario, we face the need to manage multiple sessions similar to Google Accounts. Users should be able to add different accounts in separate tabs, each with its own unique content. For example, user1 may be logged in on Tab1 while user2 is logged in on Tab2.

Our frontend is built using Angular and our backend is JAVA.

We're considering utilizing local storage in the frontend to store an array of users. The current user will then be passed in the URL. For instance, in Tab1 the URL would be http://localhost:8080/account/user1/, and in Tab2 it would be http://localhost:8080/account/user2/

The issue arises when dealing with HttpSession, as it would differ in each case. Attributes are set in the HttpSession within the code. It's my understanding that the ServletContainer manages sessions separately, identifiable by sessionId. The challenge lies in passing the sessionId in the request to Java so that the server code can access the appropriate session. For example, if tab1 is open, the session related to user1 should be selected, and if tab2 is open, the session tied to user2 should be accessed.

Answer №1

Utilize the Spring Session API with version 1.3.4.RELEASE as detailed in the official documentation here.

The Spring Session offers an API and implementations for effectively managing a user's session data.

Handling Multiple Browser Sessions - Spring Session allows for the management of multiple users' sessions within a single browser instance (similar to how Google handles multiple authenticated accounts).


Please be advised that this capability has been removed from version 2.1.2.RELEASE

11.4. Dropped Support

Due to changes in HttpSessionStrategy and its alignment with reactive world counterparts, support for managing multiple users' sessions in one browser instance has been eliminated. The introduction of a new API to replace this functionality is currently being considered for upcoming releases.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Cannot locate the Hibernate-Component class

I'm struggling to figure out what's happening here. This is the exception that keeps popping up: SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener org.springfr ...

Failure to display masonry arrangement

I am working on creating a stunning masonry layout for my webpage using some beautiful images. Take a look at the code snippet below: CSS <style> .masonryImage{float:left;} </style> JavaScript <script src="ht ...

The Angular carousel fails to display or operate properly

I am encountering an issue where the content is not displaying when using the angular-carousel directives: <ul rn-carousel rn-carousel-controls rn-carousel-index="carouselIndex" rn-carousel-buffered > <li ng-repeat="slide in slides track by ...

Using Java 8 Lambdas to Reset a Variable Conditionally Before Populating

Looking for a solution using lambdas in Java to populate a JSONArray based on a condition within the lambda. If condition x is met, I need to clear and reset the JSONArray, otherwise append values to it. However, due to the requirement of effectively fin ...

When combining Socket.io 1.0 with express 4.2, the outcome is a lack of socket connection

According to the title, I am attempting to integrate socket.io 1.0.4 with express 4.2, but all requests with "/?EIO" are resulting in a 404 error. Below are my file configurations: ./bin/www : #!/usr/bin/env node var debug = require('debug')(& ...

Can you explain the variance between using querySelector() and getElementById/getElementsByClassName/getElementsByTagName()?

I'm confused about the distinction between using querySelector() and getElementById(). From what I understand, querySelector is able to retrieve an element using any selector, giving it more flexibility. Are there additional contrasts between the two ...

How to inject a variable into an AngularJS service that utilizes both $http and $interval functions?

Struggling with $http and $interval, I stumbled upon this code. http://embed.plnkr.co/fSIm8B/script.js I forked it here: http://plnkr.co/edit/Al8veEgvESYA0rhKLn1q To make it more functional, how can I pass a variable to the service? Here is the broken ...

What is the process by which JavaScript evaluates the closing parenthesis?

I'm currently working on a calculator project that involves evaluating expressions like (5+4). The approach I am taking is to pass the pressed buttons into an array and then create a parse tree based on the data in that array. One issue I'm faci ...

Getting field values from Firestore in a React application

Within my firestore document, I have three fields that store boolean values critical for subsequent processing. To access these boolean values in my program, I need to figure out how to read the fields of a document. This process should be straightforward, ...

Is it possible to use function declaration and function expression interchangeably?

As I dive into learning about functions in Javascript, one thing that's causing confusion for me is the difference between function declaration and function expression. For example, if we take a look at this code snippet: function callFunction(fn) { ...

Enhancing React Flow to provide updated selection and hover functionality

After diving into react flow, I found it to be quite user-friendly. However, I've hit a roadblock while attempting to update the styles of a selected node. My current workaround involves using useState to modify the style object for a specific Id. Is ...

ReactJS - troubleshooting webcam video stream issue

I can't figure out why this code is not working properly. I am able to access the camera stream and see the light on my camera indicating that it's working, but the stream doesn't seem to be attaching correctly. class VideoOutput extends ...

Setting ng-click on a custom element directive in Angular 1.x: A guide

Within this code, I have assigned ng-click to a custom element directive with the expectation that clicking the rendered text would trigger an alert saying "Worked from directive!" However, the functionality does not seem to be working as intended. Althou ...

Removing Chrome cache cookies through shortcut

I'm attempting to use Java robot class methods to simulate the shortcut for clearing cache and cookies in Chrome. However, I'm encountering an issue where the key combination SHIFT+Ctrl+E does not work as expected. Could this be due to security r ...

The failure of a unit test involving Jest and try-catch

I am facing an issue with creating unit tests using jest. exportMyData.js const createJobTrasferSetArray = async () => { const data = exportData(); const jobTransferSet = []; try { data.forEach((element) => { const JobPathArray = el ...

Error message: 'JSF selectonemenu cannot create instance of the class'

I am attempting to create a select one menu object in my JSF application, but encounter a 'can't instantiate class' exception when trying to populate the list. Below is the code snippet from my bean: @ManagedBean(name = "districtController" ...

Issues persist with Ajax form submissions; the submitted data never seems to go through

I have encountered variations of this issue multiple times, but despite analyzing numerous examples, I am unable to determine why my code is not functioning properly. <script> $('document').ready(function(){ $('datafixForm' ...

"Effortlessly Engage Users with Rails and AJAX Comment Posting

Running a simple blog app dedicated to video game reviews, I encountered an issue with AJAX. As a self-taught student developer, I'm facing a challenge where posting comments on review pages triggers a full page refresh instead of dynamically updating ...

The Correct Approach for Implementing Error Handling in a Node.js API Server

In my Node.js API server, I encountered an issue with error handling. To tackle this problem, I developed a module specifically for error handling. When in development mode, this module sends JSON objects containing errors to the API client. Here is an exa ...

Transform a list of file directories into a JSON format using ReactJS

I am developing a function that can convert a list of paths into an object structure as illustrated below; this script will generate the desired output. Expected Output data = [ { "type": "folder", "name": "dir1& ...