gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 22:31:52 28 4
gpt4 key购买 nike

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

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

最佳答案

JSESSIONID cookie 在创建 session 时创建/发送。当您的代码第一次调用 request.getSession()request.getSession(true) 时,将创建 session 。如果您只想获取 session ,但如果 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' 页面指令关闭,在这种情况下, session 变量在 JSP 页面上根本不可用。

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

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