Home > front end >  Why does it have to be for the session with the request for
Why does it have to be for the session with the request for

Time:11-04

Consult the great god, the servlet request is built-in object encapsulates the client to request data from the server, and only the client operation data submitted to come
But the session object is in the presence of server-side, why get the session is to use request access to, rather than the response?

CodePudding user response:

The session id in the cookie

CodePudding user response:

The session is based on a cookie, so take the session must have a cookie, and tomcat is packages cookie in the request, so use the request to pick up,

CodePudding user response:

Because the service side, although the session, but I don't know which client session and corresponding, so need to carry a session id when the client request, the server side to find the corresponding session through the id associated with the client, so the server simply get the session meaningless, because I don't know what is the client, only from the client to get the session to be meaningful,

CodePudding user response:

The implementation mechanism of the session is Mr Into a sessionid, then put the data on the server, the sessionid into the cookie sent by the response to the browser, the browser to access the next time, will bring the sessionid in request cookies, and then through the sessionid to capture the actual data in the server's cache, so get sesssion depends on the request of the sessionid, through to the request to get is the most reasonable design way,

Of course, if the httpserver stubbornly designed nor not accessed by the response, after all the response and request is one-to-one, just as logic is not smooth,
  • Related