...
This represents the standard way of handling sessions via cookies as described in https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies and https://javarevisited.blogspot.com/2012/08/what-is-jsessionid-in-j2ee-web.html What is JSESSIONID in Java Web application.
Current HTTP Frameworks usually support automatic handling of cookies, so you don’t have to take care of the above procedure yourself. In the Apache HTTP Components, for example, creating the HttpClient as follows suffies already:
...