如何防止 JSESSIONID 显示在 URL 中

Pra*_*ash 5 java servlets jsessionid google-cloud-datastore

我已经使用 Google Datastore 在 servlet 中创建了一个登录页面,它工作正常。但有时它会在 URL 中显示 JSESSIONID。

如何阻止 JSESSIONID 通过 URL 发送?为什么它通过 URL 而不是请求消息传递?

VHS*_*VHS 5

在您的web.xml.

<session-config>
    <tracking-mode>COOKIE</tracking-mode>
</session-config>
Run Code Online (Sandbox Code Playgroud)

这将指示容器客户端支持 cookie,因此无需将 cookie 放入JSessionIdURL 中。


Koh*_*URA 3

你正在用response.encodeURL()吗 ?如果是这样,请尝试将其删除或禁用“URL 重写”并检查 URL。

也可以看看:

  • 禁用URL重写

Apache Tomcat 配置参考

附加信息

response.encodeURL(URL)添加;jsessionid=xxxx...到网址。要禁用此功能(=“URL 重写”),

Tomcat 7.0 或更高版本:

<session-config>
  <tracking-mode>COOKIE</tracking-mode>
</session-config>
Run Code Online (Sandbox Code Playgroud)

汤姆猫6.0:

<Context disableURLRewriting="true" ...
Run Code Online (Sandbox Code Playgroud)