Java SessionID:如何获取 GET SessionID 参数的名称?
似乎 GET 请求中代表 SessionID 的参数名称(如 Tomcat 中的 jsessionid=XXXXXXXXXXXXXXXXXXXXXXXXXX)在 servlet-spec 中未标准化?如何获取 SessionID 的(Servelt 容器特定)名称? (至少在Websphere中似乎可以更改SessionID-Parameter-Name的名称)
=>根本问题是,我需要始终使用会话 ID 对 servlet 中的 URL 进行编码。但似乎“response.encodeURL()”方法仅在禁用 Cookie 的情况下才会执行此操作(=>因此使用 URL 重写和 URL 中的 sessionID)。
在 Servlet 中始终使用会话 ID 对 URL 进行编码的替代方案是什么?由于第一个问题意味着我想自己构建 sessionid,但因此我需要 sessionID-参数名称,但它似乎没有标准化,所以我以某种方式需要从某处获取参数名称...)
更新: 目的是保留 Servlet-Container 提供的会话管理功能,而不是完全关闭它。我需要将回调 URL 传递给我希望始终包含 SessionURL 的第三方系统。所以我只想始终使用 sessionID 对这个单个 URL 进行编码,以最大程度地减少任何安全问题...
非常感谢 扬
it seems that the Parameter-Name in the GET request, that represents the SessionID (like jsessionid=XXXXXXXXXXXXXXXXXXXXXXXXXX in Tomcat) is not standardized in the servlet-spec? How can I get the (Servelt Container Specific) name of the SessionID? (At least in Websphere there seems to be the possibilty to change the name of the SessionID-Parameter-Name)
=> The underlaying problem is, I need to encode a URL in a servlet ALWYAS with the session ID. But it seems that the "response.encodeURL()" Method only does this if Cookies are disabled (=>therefor using URL-Rewriting with the sessionID in the URL).
What would be an alternative to always encode a URL with a session ID in a servlet? As the first question implies I wanted to build the sessionid on my own but I therefore need the sessionID-Parameter Name that however seems not be be standardized, so I somehow need to get the Parameter-Name from somewhere...)
UPDATE:
The intention is to keep the SessionManagement Functionality provided by the Servlet-Container and not turn it off completely. I need to pass a Callback URL to a third party system that I want to always contain the SessionURL. So I only want to encode this single URL always with the sessionID to minimize any security issues...
Thank you very much
Jan
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
jsessionid
实际上并不是请求参数,它被编码到 URL 本身,然后在到达控制器之前由容器进行解码和删除。 jsessionid 本身的值可以从 HttpSession.getId() 中检索。如果您想阻止 Tomcat 使用 cookie,那么您可以在
WEB-INF
下提供一个特定于 tomcat 的context.xml
文件,其中包含如下内容:然后,tomcat 应该自动将所有会话 ID 编码到 URL 上。
The
jsessionid
isn't actually a request parameter, it's encoded on to the URL itself, and then decoded and removed by the container before it gets as far as your controller. The value of jsessionid itself can be retrieved fromHttpSession.getId()
.If you want to stop Tomcat from using cookies, then you can provide a tomcat-specific
context.xml
file underWEB-INF
, containing something like this:This will disable all cookies for that webapp, and tomcat should then automatically encode all session IDs on to the URL instead.