gpt4 book ai didi

java - 在什么条件下创建 JSESSIONID?

转载 作者:bug小助手 更新时间:2023-10-28 10:39:33 26 4
gpt4 key购买 nike

创建JSESSIONID的时间/条件是什么?

是每个域吗?例如,如果我有一个 Tomcat 应用程序服务器,并且我部署了多个 Web 应用程序,是否会为每个上下文(Web 应用程序)创建一个不同的 JSESSIONID,或者它是否在 Web 应用程序之间共享,只要它们是同一个域?

最佳答案

JSESSIONID cookie 在创建 session 时创建/发送。 Session 在您的代码第一次调用 request.getSession()request.getSession(true) 时创建。如果您只想获取 session ,但如果它不存在则不创建它,请使用 request.getSession(false) - 这将返回一个 session 或 null。在这种情况下,不会创建新 session ,也不会发送 JSESSIONID cookie。 (这也意味着 session 不一定是在第一次请求时创建的...您和您的代码可以控制何时创建 session )

session 是每个上下文的:

SRV.7.3 Session Scope

HttpSession objects must be scoped at the application (or servlet context) level. The underlying mechanism, such as the cookie used to establish the session, can be the same for different contexts, but the object referenced, including the attributes in that object, must never be shared between contexts by the container.

( Servlet 2.4 specification )

更新:如果还没有 session ,则每次调用 JSP 页面都会隐式创建一个新 session 。这可以使用 session='false' 页面指令关闭,在这种情况下,JSP 页面上根本没有 session 变量。

关于java - 在什么条件下创建 JSESSIONID?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/595872/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com