问题描述
是否可以通过Servlet API为HTTP会话分配自定义ID?
Is it possible to assign a custom ID to a HTTP session through Servlet API?
我知道来自任何应用服务器的会话处理,例如Tomcat,这已经足够了很好地生成唯一ID。但是我根据每个用户和时间的信息定制了唯一的会话ID,因此不会重复。
I know that session handling from any application server, Tomcat for example, it's enough good to generate unique IDs. But I have custom unique session IDs based on information per user and time, so it won't be repeated.
我查看了有关会话处理的所有文档,但我无处可去找到我需要的东西。
And I looked at every documentation about session handling but nowhere I find what I need.
这是一个项目的要求,所以如果不可能,我需要知道原因(或者它只能通过API获得?)。
It's a requirement for a project, so if it's not possible, I need to know the reasons (or it's only not available through API?).
推荐答案
如果您使用的是Tomcat,则可以创建自定义会话管理器(请参阅)。然后,您可以访问Tomcat object并且可以调用setId。
If you are using Tomcat, you may be able to create a custom session manager (see this discussion). You would then have access to the Tomcat Session object and could call setId.
这篇关于Java Servlet API在会话处理中的自定义ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!