Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How Tomcat handles session internally? [closed]

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

  1. Hidden Form Fields
  2. URL Rewriting
  3. Cookies

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

Is Tomcat using cookies or others also?

like image 791
Mawia Avatar asked Jul 24 '13 12:07

Mawia


People also ask

How does Tomcat maintain session?

In session management, Tomcat creates a session id whenever client's first request gets to the server (However, other servlet containers may behave differently). Then it inserts this session id into a cookie with a name JSESSIONID and sends along with the response.

How does Tomcat store session data?

Tomcat's sessions are stored according to chosen session manager. If we pick the standard manager (StandardManager class saw previously), all session data will be saved into Java heap.

How does Tomcat handle concurrent requests?

APR allows Tomcat to use Apache server libraries to further enhance its capabilities as a web server. NIO mode enables Tomcat to simultaneously handle multiple connections per thread by using poller threads to keep connections alive and worker threads to process incoming requests.

Does Tomcat use log4j by default?

Apache Tomcat. Log4j may be used as the logging framework for Apache Tomcat. This support is implemented automatically by including the log4j-api, log4j-core, and log4j-appserver jars in the boot classpath. A file named log4j2-tomcat.


1 Answers

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.

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.

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

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

and disable the url re-writing the same way :

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

Even read this Servlet Session Tracking with cookies (JSESSIONID)

like image 126
AllTooSir Avatar answered Oct 18 '22 00:10

AllTooSir