Work with sessions in the GWT application

I have a GWT application that has an RPC service on it. I'm currently trying to implement user support, and the only question that still remains is how to store session data.

I save the session id using

getThreadLocalRequest().getSession().setAttribute("sid", "randomSIDgoeshere");

So the first question is more for Java servlets than for GWT. This code ensures that next time I make this call:

getThreadLocalRequest().getSession().getAttribute("sid");

It will be either null (if it is called for a user who has not yet visited the code fragment where the SID attribute is set), or it will be exactly the same SID that I already saved for this user. In other words, are these 2 pieces of code specific to the user? (by user I mean a single browser on one computer)

The second question is how to keep the mappings between the SID and some additional data, such as a user ID. In case I have a code like this:

public class MyGwtServiceImpl extends RemoteServiceServlet implements MyGwtService {
  // SID to User ID mappings
  private final Map<String, String> sessions = 
    new HashMap<String, String>();
  ...
}

Is it guaranteed that sessionsit is always the same object for all requests, and its data will remain "alive" if the entire application is not completed? (For example, Tomcat is stopped) Is this the usual approach or do I need to save all these mappings in my DB?

+5
source share
1 answer

Firstly:

, . getThreadLocalRequest().getSession().getAttribute("sid"); sid . , , , ( + ip) . :

:

  • A Firefox
  • X Y

1

  • A Firefox
  • X

2

  • A Google Chrome
  • X

3

  • B Firefox
  • X

, . , , , .

-:

, . isletance, , . , Static, THAT . ServeletContext

, (, Glassfish) , ( , (Glassfish )). , , , , .

+7

All Articles