My environments:
Sometimes the url of the link includes jsessionid Please see the below:
<a href="/VocabDB-1.0/MyVocab/Index;jsessionid=UGGha-TULRrZNFqQdtqdVlpBQQEDE-WwRrj4l78P.gpcit2ua7371tv9">Test Link</a>
Most of the time the link is
<a href="/VocabDB-1.0/MyVocab/Index">Test Link</a>
Any ideas? Thanks!
That's perfectly normal: on the first request, the server has no idea if the client accepts cookies or not, so it sends a cookie and it also stores the session ID in the URL.
On the second request, if it receives the session ID from the cookie, it knows that adding it to the URL is not necessary anymore for that session, and thus stops doing it.
That's, BTW, what the javadoc of encodeURL explains already:
Encodes the specified URL by including the session ID, or, if encoding is not needed, returns the URL unchanged. The implementation of this method includes the logic to determine whether the session ID needs to be encoded in the URL. For example, if the browser supports cookies, or session tracking is turned off, URL encoding is unnecessary.
For robust session tracking, all URLs emitted by a servlet should be run through this method. Otherwise, URL rewriting cannot be used with browsers which do not support cookies.