Q:

Cookies for different user in one browser

There is some drop down on the page of web site (user has access to this page only if he/she is authenticated) an I want to save this value to cookies and set it back to drop down when user gets back to my site. 
It is not a problem to save currently selected drop down option value to cookie and retrieve it later. But I faced with some problem if I make login at the same browser by another user. It gets from cookies value what was saved by previous user. 
So what is good way to separate cookies for different users from the same browser? I was thinking about create cookie with name like 'username-dropdown' but I have some doubts that it is the best solution.
I use Java with Tomcat 8.

A:

I'm going to take a guess here that you don't need this information sent to your server with each and every HTTP request; you just need to store the information client-side (and you can send it to the server as necessary via ajax).
If so, I'd use local storage, not cookies. And sure, using the username or user ID or some such is reasonable:
// Setting:
localStorage.setItem(username + "-dropdown", value);

// Getting:
var value = localstorage.getItem(username + "-dropdown");

Or you can use brackets notation:
// Setting:
localStorage[username + "-dropdown"] = value;

// Getting:
var value = localstorage[username + "-dropdown"];

Pretty much the only reason not to use brackets notation is if you need to polyfill local storage on older browsers (there are polyfills that fall back to cookies for you), but local storage is supported on all modern browsers, and also IE8, so those browsers really are very out of date at this point.

