Servlet sessions are supported where?

In Servlets, we can use the session tracking feature. Therefore, I just want to ask that the sessions are supported on the client side or on the server.

If it's on customers, then where?
Can I create a session on a client HTTPSession?

I found one article that says sessions on client and server sites can be supported.

+4
source share
2 answers

This is the server that will support the sessions. And the server is responsible for session resolution. Customers do not have to worry about sending any information explicitly. Since the Client can send Cookies stored on the client with each request, the server can use Cookies to track sesssion.

Note. Cookies are just one way to implement session tracking. This is also the best way.

Thus, the server uses cookies as one of the ways to handle session tracking.

This can be done in other ways:

URL rewriting - the application / server should add a session identifier in all URLs / links. When they are called from the client, the session comes to the server along with the URL.

Hidden form fields . Forms may contain a hidden input type with a session identifier as the field value. When the form is submitted, the session identifier is followed by the form data.

+4
source

The session is located on the server side on the client side, we have cookies (or jsessionId or hidden form fields) to match the request with the server session


How does he compare

When you send a request for the first time (from the very beginning), the server gives you a cookie with the response they send, your browser accepts this cookie, which contains the expiration date, contents (some lines) and domain name now that you send the request to the server again, your browser will add this cookie for this domain to the header, so when the server receives the request, it sees the cookie from the header and displays its contents with sessionId on the server


Fyi

You can also have a session in other applications (e.g. peer-to-peer application)

+3
source

Source: https://habr.com/ru/post/1394112/


All Articles