Wildfly (Undertow) 有时在 URL 中包含 jsessionid

Wildfly (Undertow) includes jsessionid in URL sometimes

我的环境:

有时link的url包含jsessionid请看下面:

<a href="/VocabDB-1.0/MyVocab/Index;jsessionid=UGGha-TULRrZNFqQdtqdVlpBQQEDE-WwRrj4l78P.gpcit2ua7371tv9">Test Link</a>

大多数时候link是

<a href="/VocabDB-1.0/MyVocab/Index">Test Link</a>

有什么想法吗?谢谢!

这很正常:在第一次请求时,服务器不知道客户端是否接受 cookie,因此它发送一个 cookie 并且 它还将会话 ID 存储在URL.

在第二个请求中,如果它从 cookie 中接收到会话 ID,它知道将它添加到 URL 中对于该会话不再是必需的,因此停止这样做。

也就是说,顺便说一句,javadoc of encodeURL 已经解释了什么:

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.