在什么条件下创建了JSESSIONID? [英] Under what conditions is a JSESSIONID created?

查看:151
本文介绍了在什么条件下创建了JSESSIONID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

When / what are the conditions when a JSESSIONID is created?

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

Is it per a domain? For instance, if I have a Tomcat app server, and I deploy multiple web applications, will a different JSESSIONID be created per context (web application), or is it shared across web applications as long as they are the same domain?

推荐答案

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

JSESSIONID cookie is created/sent when session is created. Session is created when your code calls request.getSession() or request.getSession(true) for the first time. If you just want to get the session, but not create it if it doesn't exist, use request.getSession(false) -- this will return you a session or null. In this case, new session is not created, and JSESSIONID cookie is not sent. (This also means that session isn't necessarily created on first request... you and your code are in control when the session is created)

会话是根据具体情况:


SRV.7.3会话范围

SRV.7.3 Session Scope

HttpSession对象的作用域必须是
应用程序(或servlet上下文)
级别。底层机制,例如用于建立
会话的cookie的
,对于不同的
上下文可以是相同的,但是引用的对象,
包括该$ b中的属性$ b对象,绝不能在容器之间的
上下文之间共享。

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规范

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

Update: Every call to JSP page implicitly creates a new session if there is no session yet. This can be turned off with the session='false' page directive, in which case session variable is not available on JSP page at all.

这篇关于在什么条件下创建了JSESSIONID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆