title: Get sessionCookieName from ServletContext in context.xml of tomcat
body: <p>How could I get the name of session of current request?</p>
  
  <p>The default name of tomcat session is "jsessionid". Given that I have modified the sessionCookieName configuration in context.xml of tomcat as below to gives multiple tomcat instance run on a same server</p>
  
  <pre><code>&lt;Context sessionCookieName="appSessionId"&gt;
  
  &lt;!-- Default set of monitored resources. If one of these changes, the    --&gt;
  &lt;!-- web application will be reloaded.                                   --&gt;
  &lt;WatchedResource&gt;WEB-INF/web.xml&lt;/WatchedResource&gt;
  &lt;WatchedResource&gt;${catalina.base}/conf/web.xml&lt;/WatchedResource&gt;
  
  &lt;!-- Uncomment this to disable session persistence across Tomcat restarts --&gt;
  &lt;!--
  &lt;Manager pathname="" /&gt;
  --&gt;
  
  &lt;!-- Uncomment this to enable Comet connection tacking (provides events
       on session expiration as well as webapp lifecycle) --&gt;
  &lt;!--
  &lt;Valve className="org.apache.catalina.valves.CometConnectionManagerValve" /&gt;
  --&gt;
  &lt;/Context&gt;
  </code></pre>
  
  <p>My web app need to know what the name of session of current request is. I have tried such as:</p>
  
  <pre><code>request.getServletContext().getSessionCookieConfig().getName()
  request.getSession().getServletContext().getSessionCookieConfig().getName()
  </code></pre>
  
  <p>But both of them are null.</p>
  
  <p>My pom.xml as below</p>
  
  <pre><code>&lt;dependency&gt;
      &lt;groupId&gt;javax.servlet&lt;/groupId&gt;
      &lt;artifactId&gt;javax.servlet-api&lt;/artifactId&gt;
      &lt;version&gt;3.0.1&lt;/version&gt;
  &lt;/dependency&gt;
  
  &lt;dependency&gt;
      &lt;groupId&gt;org.apache.tomcat&lt;/groupId&gt;
      &lt;artifactId&gt;tomcat-catalina&lt;/artifactId&gt;
      &lt;version&gt;8.0.23&lt;/version&gt;
  &lt;/dependency&gt;
  </code></pre>
  
  <p>The tomcat I have used is also 8.0.23, any help is appreciated.</p>