The servlet container will handle this for you. If you look at the URL the first time you put your site, it will use rewriting the URL to add the JSESSIONID to the URL.
This is because the first time the server responds to the client, it does not know if the client supports cookies or not. He also wrote a cookie with a session identifier, so in the second request he checks the cookie, and if it stops using re-writing the URL, if it is not running.
source share