每个请求都有一个新的 HttpSession?
在使用 servlet 规范开发应用程序时,我一直认为理所当然地认为为给定客户端的每个新请求创建的 JSESSIONID cookie 是理所当然的。但仔细思考一下,servlet 容器仅在代码中请求并创建会话之后创建 cookie 标头不是更合乎逻辑吗?对于禁用 cookie 的客户端,最终不会为每个发出的请求创建一个新的 HttpSession
吗?
如果问题仍然不清楚,请告诉我,以便我可以编辑它。 TIA。
I've always taken for granted the JSESSIONID
cookie created for every fresh request for a given client when developing applications using the servlet specification. But after giving it a bit of thought, isn't is more logical for the servlet container to create a cookie header only after the session has been requested and created in code? For clients who have their cookies disabled, won't it end up creating a new HttpSession
for each request made?
Please let me know if the question is still unclear so I can edit it. TIA.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
默认情况下,Servlet 容器不会创建新的 Session,除非 Servlet 实际上显式创建了它。仅仅因为在标头中填充了 JSEESIONID 并不意味着服务器上必须有一个 seesion。对此的一个例外是在 JSP 中,如果会话不存在,则默认情况下会创建一个会话,除非 <%@ page session="false" %>
就没有打开 cookie 而言:
A new Session will not be created by the Servlet container by default unless the Servlet actually creates it explicitly. Just because in the Header a JSEESIONID is being populated does not mean that there has to be a seesion on the server. An exception to this is in JSPs that by default create a Session if one is not there unless <%@ page session="false" %>
As far as not having cookies turned on: