java Tomcat 如何在内部处理会话?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17834144/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How Tomcat handles session internally?
提问by Mawia
From my understanding, Servlet Containers handle session using some HTTP protocols like,
根据我的理解,Servlet Containers 使用一些 HTTP 协议来处理会话,例如,
- Hidden Form Fields
- URL Rewriting
- Cookies
- 隐藏表单域
- 网址重写
- 饼干
I'm curious how Apache Tomcathandles the session internally, though it's irrelevant to average developers.
我很好奇Apache Tomcat如何在内部处理会话,尽管它与普通开发人员无关。
Is Tomcat using cookies or others also?
Tomcat 是否也在使用 cookie 或其他?
采纳答案by NINCOMPOOP
By default, Tomcat directly sends cookies in the HTTP response , like SET COOKIE:JSESSIONID....
back to the browser and rewrites the URL to add a JSESSIONID
parameter in it , for the first request, so that it can fall back on the later in case cookiesare disabled in the client browser.
默认情况下,Tomcat 直接在 HTTP 响应中发送 cookie,例如SET COOKIE:JSESSIONID....
返回浏览器并重写 URL 以JSESSIONID
在其中添加一个参数,用于第一个请求,以便在客户端禁用cookie的情况下可以回退到后面浏览器。
The next time if the browser requests the server with the JSESSIONID
in its request
, Tomcat will use the JSESSIONID
cookie for maintaining the session.
如果浏览器请求服务器与下一次JSESSIONID
在request
,Tomcat将使用JSESSIONID
的cookie维持会话。
You can overide the session cookie behavior in Tomcat by modifying context.xml:
您可以通过修改context.xml来覆盖 Tomcat 中的会话 cookie 行为:
<Context cookies="false">
</Context>
and disable the url re-writing the same way :
并以相同的方式禁用 url 重写:
<Context disableURLRewriting="true">
</Context>
Even read this Servlet Session Tracking with cookies (JSESSIONID)
回答by tariq khan
Tomcat sends cookies by default unless they are blocked by the user from the browser (though this practice is not encouraged). Moreover, the session cookies (JSESSIONID) that are created are not persistent cookies and they die off whenever that instance(window) of the browser is closed.
默认情况下,Tomcat 会发送 cookie,除非它们被用户从浏览器阻止(尽管不鼓励这种做法)。此外,创建的会话 cookie (JSESSIONID) 不是持久性 cookie,只要浏览器的该实例(窗口)关闭,它们就会消失。