Tomcat如何在内部处理会话? [英] How Tomcat handles session internally?

查看:112
本文介绍了Tomcat如何在内部处理会话?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据我的理解,Servlet Containers使用一些HTTP协议来处理会话,例如,

From my understanding, Servlet Containers handle session using some HTTP protocols like,


  1. 隐藏表单字段

  2. 网址重写

  3. Cookie

我很好奇 Apache Tomcat 在内部处理会话,虽然它与普通开发人员无关。

I'm curious how Apache Tomcat handles the session internally, though it's irrelevant to average developers.

Tomcat是否也使用cookie或其他?

Is Tomcat using cookies or others also?

推荐答案

默认情况下,Tomcat直接在HTTP响应中发送cookie,如 SET COOKIE:JSESSIONID .... 返回浏览器并重写URL以在第一个请求中添加 JSESSIONID 参数,以便在 cookies 在客户端浏览器中被禁用。

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 cookies are disabled in the client browser.

下次如果浏览器在其服务器中请求 JSESSIONID request ,Tomcat将使用 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.

您可以通过修改 context.xml 来覆盖Tomcat中的会话cookie行为:

You can overide the session cookie behavior in Tomcat by modifying context.xml:

<Context cookies="false">
</Context>

并禁用网址重写方式:

<Context disableURLRewriting="true">
</Context>

即使阅读此使用cookie进行服务会话跟踪(JSESSIONID)

这篇关于Tomcat如何在内部处理会话?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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